user1256477
user1256477

Reputation: 11201

navigation view doesn't work first click

I have a navigation view, when I click, I just show the row number.

In the mainView:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if (read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   
}

[read updateRowNumber:indexPath.row];

[[self navigationController] pushViewController:read animated:YES];

and in my readNotice class:

-(void)updateRowNumber:(int)theindex {

rowNumber = theindex + 1;

message.text = [NSString stringWithFormat:@"row %i was clicked", rowNumber];

NSLog(@"view did load row = %d", rowNumber);

}

readNotice.xib only contents a Label.

First time I click it shows "Label", but it works the following tries.

I suppose I need to initiliaze something that I missed, but I cant find it.

Thank you in advance

Upvotes: 0

Views: 106

Answers (3)

rakeshNS
rakeshNS

Reputation: 4257

Try this, in tableview:didSelectRowAtIndex method,

 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 if (read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   
 }

 read.index = indexPath.row;
 [[self navigationController] pushViewController:read animated:YES];

create a instance variable in readNotice as

     @property(assign) int index;

     @synthesize index;

In readNotice viewDidLoad method, you just call updateRowNumber

 - (void)viewDidLoad 
 {
   [super viewDidLoad];
   [self updateRowNumber:index];
 }

It will display the number as you expected

Upvotes: 0

Abhishek
Abhishek

Reputation: 2253

I m not able to understand why you made read variable .... ? use this ..

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

  readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
  [self.navigationController pushViewController:aController  animated:YES];
  [aController updateRowNumber:indexPath.row];
}

may this will help you...

Upvotes: 2

rishi
rishi

Reputation: 11839

Use -

if (self.read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   

}
--------
---------

[[self navigationController] pushViewController:self.read animated:YES];

Upvotes: 0

Related Questions