简体   繁体   English

TableView-选择单元格时的操作

[英]TableView - action when cell is selected

I have some cells which perform a seque, but I want one cell to log the current user out. 我有一些单元格可以执行定序操作,但是我希望一个单元格可以将当前用户注销。 How can I set this action to a single cell? 如何将此操作设置为单个单元格?

thx, Tim. 蒂姆,蒂姆

You could implement shouldPerformSegueWithIdentifier:sender: and return NO for the indexPath of the cell that you want to log out the user. 您可以实现shouldPerformSegueWithIdentifier:sender:,并为要注销用户的单元格的indexPath返回NO。 The sender argument will be the cell, so you can get the indexPath from that. sender参数将是该单元格,因此您可以从中获取indexPath。 If you wanted the first cell to log out the user, you could do this, 如果您希望第一个单元注销用户,则可以执行此操作,

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(UITableViewCell *)sender {

    NSIndexPath *path = [self.tableView indexPathForCell:sender];
    if (path.row == 0) {
        // log out the user here
        return NO;
    }else{
        return  YES;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // User selected a row, so check if it's the logout row or not
    if (indexPath.row == logoutRowIndex) {
        // Logout
        [self logout];
    } else {
        // Perform segue
        [self performSegueWithIdentifier:@"segueIdentifier"];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在选定的表视图单元格中执行NSRegularExpression操作 - Perform NSRegularExpression action in a selected tableview cell 轻按Tableview单元格时显示操作表 - Displaying action sheet when tableview cell is tapped 当选择单元格时,TableVIew中的UIImage移动 - UIImage in TableVIew moves when cell is selected 在swift中选择时,Tableview单元格返回nil - Tableview cell returns nil when selected in swift 选择单元格时奇怪的 tableview 行为 - weird tableview behavior when cell is selected Swift - 选择 TableView 单元格时的动画 (didSelectRowAtIndexPath) - Swift - Animating When TableView Cell Selected (didSelectRowAtIndexPath) 选择表格视图单元格时创建自定义视图 - Creating a custom view when a tableview cell is selected 选择tableView单元格时更改单元格上的按钮图像 - Change button image on a cell when a tableView Cell is selected 选择单元格后,Swift tableView单元格子视图闪烁(消失,然后重新出现) - Swift tableView cell subviews flicker (disappear and then reappear) when cell is selected 在每个单元格都包含表格视图的表格视图中选择新单元格时,无法取消选择先前选择的单元格 - Can’t deselect previously selected cell when a new one is selected in a tableview where each cell contains tableview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM