相关疑难解决方法(0)

单击来自Cell的Button获取UITableViewCell的indexPath

请看这个图像

我在有一个按钮(红色交叉)UITableViewCell,并在该按钮,我想获得的点击indexPathUITableViewCell.

现在我正在为每个按钮分配标签,这样 cell.closeButton.tag = indexPath.section 按下按钮我得到的indexPath.section值如下:

@IBAction func closeImageButtonPressed(sender: AnyObject) {
  data.removeAtIndex(sender.tag)
  tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

这是正确的实施方式还是有其他干净的方法来做到这一点?

uibutton uitableview ios swift2

8
推荐指数
2
解决办法
2万
查看次数

UITableView Cell - 从按钮获取IndexPath.row?

我目前在单元格中定义了一个按钮,以及跟踪其UITouchDown操作的方法,如下所示:

- (void) clickedCallSign:(id)sender {

    int index = [sender tag];
    NSLog(@"event triggered %@",index);

}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    //Callsign button
    UIButton *button;

    CGRect rect = CGRectMake(TEXT_OFFSET_X, BORDER_WIDTH, LABEL_WIDTH, LABEL_HEIGHT);
    button = [[UIButton alloc] initWithFrame:rect];
    cell.tag=[indexPath row];
    button.tag=[indexPath row];
    [button addTarget:self action:@selector(clickedCallSign:) forControlEvents:UIControlEventTouchDown];
    [button setBackgroundColor:[UIColor redColor]];
    [button setTitle:@"hello" forState:UIControlStateNormal];
    [cell.contentView addSubview:button];
    [button release];   
}
Run Code Online (Sandbox Code Playgroud)

但是,当我单击模拟器中的单元格时,控制台调试消息是:"event triggered(null)",我的应用程序很快就崩溃了.

如何正确获取我的clickedCallSign方法中的indexPath.row值?

iphone objective-c selector uibutton uitableview

6
推荐指数
1
解决办法
5529
查看次数

将参数传递给选择器

我在自定义单元格中有一个UIButton,我想在用户按下该按钮时触发一个动作但是我需要知道按下UIButton的哪一行.

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;

    ...

    [button addTarget:self action:@selector(buttonPressedAction:)forControlEvents:UIControlEventTouchUpInside];

}

- (void)buttonPressedAction:(UIButton *)button
{
    //int row = indexPath.row;
    //NSLog(@"ROW: %i",row);
}
Run Code Online (Sandbox Code Playgroud)

如何将indexPath作为参数传递给我的选择器?

iphone cocoa-touch objective-c ipad ios

3
推荐指数
1
解决办法
1185
查看次数

tableViewCell的indexPath

我有一个自定义方法来检测单元格图像上的点击.我还想找到图像的相关单元格的索引路径,并在函数中使用它.这是我正在使用的:

的cellForRowAtIndexPath:

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellImageTapped:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];
Run Code Online (Sandbox Code Playgroud)

方法我试图获取索引路径:

  -(void)cellImageTapped:(id)sender {
   if(videoArray.count > 0){
       Video *currentVideo = [videoArray objectAtIndex:INDEX_PATH_OF_CELL_IMAGE];
     //do some stuff          
  }
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何传递索引路径.有任何想法吗?

cocoa-touch objective-c uitableview ios

2
推荐指数
1
解决办法
4269
查看次数