9

我想使用情节提要将静态单元与动作连接起来。问题是您无法将单元格与操作连接,因此我尝试了另一种方式。因此,在我的头文件中,我使用情节提要将此属性与静态单元格连接起来:

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

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

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

在此处输入图像描述

4

3 回答 3

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

或者

-(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.
    }
}
于 2013-03-29T11:17:11.680 回答
3

我认为您应该使用 TableView 委托方法,而不是将其与静态单元格连接

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Put your action logic here by using its index "indexPath.row".
}
于 2013-03-29T11:17:41.090 回答
1
#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([tableView cellForRowAtIndexPath:indexPath] == self.theStaticCell){
        NSLog(@"Static cell clicked");
    }
}
于 2013-03-29T11:29:42.373 回答