[英]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.