简体   繁体   中英

How to activate tableView didSelectRowAtIndexPath in 2 sections?

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 {

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
 } 
}

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.
- (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
  }
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM