将静态单元与动作连接

9 objective-c storyboard ios

我想使用故事板将静态单元格与动作连接起来.问题是你无法通过动作连接单元格,所以我尝试了另一种方式.所以在我的头文件中,我使用故事板将此属性与静态单元格连接起来:

@property (nonatomic, strong) IBOutlet UITableViewCell *theStaticCell;  
Run Code Online (Sandbox Code Playgroud)

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

所以我想使用"更新"单元格,当你点击它时,上面的代码就会被执行.

在此输入图像描述

vir*_*ral 15

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.section ==1 && indexPath.row == 0)
    {
        //Do what you want to do.
    }
}
Run Code Online (Sandbox Code Playgroud)

要么

-(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.
    }
}
Run Code Online (Sandbox Code Playgroud)