Reputation: 11
In my DetailViewController.m
, the rowNumber
value is functioning well. But when the value can't apply into viewDidLoad
the rowNumber
is zero. How can I solve this problem?
//DetailViewController.m
-(void)updateRowNumber:(int)theindex
{
rowNumber = theindex + 1;
message.text = [NSString stringWithFormat:@"row %d was clicked", rowNumber];
NSLog(@"ID #000%d", rowNumber);
}
-(void)viewDidLoad
{
message.text = [NSString stringWithFormat:@"row %d was clicked", rowNumber];
}
Upvotes: 1
Views: 69
Reputation: 13549
It's not clear what you're trying to do, but its obvious that you should be using the tableview delegate methods:
It looks like you really need the method below:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
You'd want to store the rowNumber with this:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int rowNumber = indexPath.row;
}
Or, if the row is still selected and you want to grab that index somewhere else you could do:
NSIndexPath *index = [self.tableView indexPathForSelectedRow];
int rowNumber = index.row;
But check out all the methods on the dev site:
Upvotes: 4