什么是didSelectRowAtIndexPath的controlEvent

时间:2016-07-14 12:11:36

标签: ios objective-c iphone uitableview

由于在didSelectRowAtIndexPath选择中触发UITableViewCell,因此它必须具有UIControlEventTouchUpInside之类的controlEvent(作为示例)。调用didSelectRowAtIndexPath时会触发哪个controlEvent? 我问这个问题的原因是,UITableViewCell有滑动按钮,其事件与didSelectRowAtIndexPath发生冲突。但是当我看到iPhone的默认邮件应用时,它的工作非常顺利。

2 个答案:

答案 0 :(得分:0)

您需要实施委托方法以便顺利处理滑动事件以下是一些示例 -

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Call" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

        // maybe show an action sheet with more options

        // NSIndexPath *cellIndexPath = [self.tView indexPathForCell:cell];
        // UIActionSheet *shareActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Contact Info", @"Email Conversation",@"Clear Conversation", nil];
        // shareActionSheet.tag=indexPath.row;
        // [shareActionSheet showInView:self.view];


        [self callButtonClicked:conObject.userName];

        //[cell hideUtilityButtonsAnimated:YES];

        [self.tView setEditing:NO];

    }];

    moreAction.backgroundColor=[UIColor colorWithRed:77.0/255.0 green:216.0/255.0 blue:101.0/255.0 alpha:1];

    //  moreAction.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"MobileRingIcon"]];

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete"otherButtonTitles: nil];

        sheet.tag=indexPath.row;

        [sheet showInView:self.view];

    }];

    [deleteAction setBackgroundColor:[UIColor redColor]];

    return @[deleteAction, moreAction];
}

// From Master/Detail Xcode template
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {

    } else if (editingStyle == UITableViewCellEditingStyleInsert) {

        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}

答案 1 :(得分:-1)

使用commitEditingStyle

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

注意这个方法