我在TableView單元上有一個按鈕。我的問題是,在點擊單元格和按鈕時,我們想要執行相同的操作。點擊一個單元我使用做選擇方法。他們的任何方法是點擊單元格上的按鈕,他們執行與單元格選擇執行相同的操作。單元格上的按鈕不執行操作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *simpleTableIdentifier = [NSString stringWithFormat:@"%ld CustumCell",(long)indexPath.row];
CustumCell *cell = (CustumCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustumCell" owner:self options:nil];
cell = [nib objectAtIndex:2];
UIButton *button;
UIImageView *imageView;
UILabel *nameLabel;
if (screenWidth ==320) {
imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width-40, cell.contentView.frame.size.height+47)];
button=[[UIButton alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width-40, 0, 40, cell.contentView.frame.size.height+47)];
nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width/2-40, (cell.contentView.frame.size.height+20)/2, 100, 30)];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIImageView *images = (UIImageView *)[cell.contentView viewWithTag:100];
images.image=[UIImage imageNamed:[tableImageArray objectAtIndex:indexPath.row]];
UIButton *buttond = (UIButton *)[cell.contentView viewWithTag:101];
[buttond setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
UILabel *label=(UILabel *)[cell.contentView viewWithTag:102];
label.text=[cellNameArray objectAtIndex:indexPath.row];
label.textColor =[UIColor whiteColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
table.separatorStyle = UITableViewCellSeparatorStyleNone;
table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
SelectVoucher *selectVoucher=[[SelectVoucher alloc]initWithNibName:@"SelectVoucher" bundle:nil];
selectVoucher.hotelName =[cellNameArray objectAtIndex:indexPath.row];
[self presentViewController:selectVoucher animated:YES completion:nil];
}
你可以發佈你的代碼更好的通關你做了什麼? @varun – iPeter
只需設置'button.userInteractionEnabled = NO',didSelected將被解僱,如果你想這樣做 –
thnks bddy它的工作 – varun