Tidane
Tidane

Reputation: 694

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 {

Upvotes: 1

Views: 1415

Answers (3)

Arvind
Arvind

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

Ajay Sharma
Ajay Sharma

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

CarlJ
CarlJ

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

Related Questions