Connect a static cell to an action

I want to associate a static cell with an action using a storyboard. The problem is that you cannot connect the cell to the action, so I tried it differently. So in my header file, I linked this property to a static cell using a storyboard:

@property (nonatomic, strong) IBOutlet UITableViewCell *theStaticCell; 

and

  UITableViewCell *theCellClicked = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; if (theCellClicked == _theStaticCell) { NSLog(@"Static cell clicked"); } 

Therefore, I want to use the "Update" cell so that when I click on it, the above code will be executed.

enter image description here

+8
ios objective-c storyboard
source share
3 answers
 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section ==1 && indexPath.row == 0) { //Do what you want to do. } } 

OR

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Cell will be deselected by following line. [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; UITableViewCell *staticCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; if (cell == staticCell) { //Do what you want to do. } } 
+14
source share

I think, instead of binding it to a static cell, you should use the TableView delegation method

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Put your action logic here by using its index "indexPath.row". } 
+3
source share
 #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if([tableView cellForRowAtIndexPath:indexPath] == self.theStaticCell){ NSLog(@"Static cell clicked"); } } 
+1
source share

All Articles