Reputation: 694
I have one UItableView divided in 2 sections.
How I can manage the method tableView didSelectRowAtIndexPath?
For the section 1 the method is running but for I don't know how to implement to the 2nd section.
Thanks
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Upvotes: 1
Views: 1415
Reputation: 493
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0){
if(indexpath.row == 0){
//Your code here
}
}
else if(indexPath.section == 0){
if(indexpath.row == 0){
//Your code here
}
}
}
Upvotes: 0
Reputation: 4517
Just use the delegate method of UITableView :
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
And you can differentiate within section using the below code :
if (indexPath.section == 0)
if (indexPath.section == 1)
..upto n depends on number of sections in your TableView.
Upvotes: 1
Reputation: 9481
simply:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0) {
//Your code for Section 1 with the index 0
} else {
//Your code for Section 2 with the index 1
}
}
Upvotes: 4