Iphone UITableview自定义单元格按钮点击并didSelect方法



在我的应用程序中,有一个自定义单元格,它有一个带有某些操作的按钮,而且我必须执行didSelectRowAtIndexPath方法。由于didSeleceRowAtIndex Path方法,我的按钮操作不执行。

我的代码如下所示->

-(void)tableView:(UITableView *)tableView willDisplayCell:(DriverListCell *)cell  forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.fromLbl.text=[[jobArray objectAtIndex:indexPath.row]objectForKey:@"pickup_addr"];
    cell.toLbl.text=[[jobArray objectAtIndex:indexPath.row]objectForKey:@"deliver_address"];
    [cell.arrowBtn addTarget:self action:@selector(moreInfo:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)moreInfo:(UIButton*)sender
{
   NSLog(@"more info Clicked");
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSLog(@"whole row selected");
}

我可以同时执行这两个操作吗?或者给我一些解决问题的想法。

我必须执行两个操作,一个是在自定义单元格按钮单击,另一个是整行选择。

如果单击按钮-(void)moreInfo:(UIButton*)sender,将调用此函数。

但如果您选择了单元格didselectrowatindexpath函数,则会调用该函数。

为了同时执行这两个操作,请删除uibutton,然后从didselectrowatindexpath方法中调用-(void)moreInfo:(int)index函数,以便同时执行两个操作。

-(void)tableView:(UITableView *)tableView willDisplayCell:(DriverListCell *)cell  forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.fromLbl.text=[[jobArray objectAtIndex:indexPath.row]objectForKey:@"pickup_addr"];
    cell.toLbl.text=[[jobArray objectAtIndex:indexPath.row]objectForKey:@"deliver_address"];
}
-(void)moreInfo:(int)index
{
    NSLog(@"more info Clicked");
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self moreInfo:indexpath.row];
    NSLog(@"whole row selected");
}

最新更新