1

我有 iphone 应用程序,我在其中向单元格添加按钮,当我单击该按钮时,它应该在按钮操作中为我提供该按钮的标题。

if (tableView==groupTableView) {
        GroupData*theData=[groupArray objectAtIndex:indexPath.row];
        cell.textLabel.font=[UIFont fontWithName:@"Helvetica" size:16];
        cell.textLabel.text=theData.GroupTitle;

        addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //[tab1 setFrame:CGRectMake(-1,2,293,58)];

        addButton.Frame=CGRectMake(400,2,42,42);

        [addButton setTitle:@"Record Video" forState:UIControlStateNormal];
        [addButton addTarget:self action:@selector(tab1Action) forControlEvents:UIControlEventTouchUpInside];
        [addButton setImage:[UIImage imageNamed:@"popuptab1j.png"] forState:UIControlStateNormal];

        addButton.clipsToBounds=YES;           
        [cell addSubview:addButton];

        return cell;     
}

-(void)tab1Action {    
     NSLog(@"Cell Tab1 Clicked %@",clicked);
}

当我单击此添加按钮时,它显示所选按钮的组标题,然后显示单击按钮的单元格的组标题。

4

1 回答 1

0

在 UITableViewCell 中设置你的按钮,标签如下: -

    addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.Frame=CGRectMake(400,2,42,42);

    [addButton setTitle:@"Record Video" forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(tab1Action:) forControlEvents:UIControlEventTouchUpInside];
    addButton.tag=indexPath.row;
    [addButton setImage:[UIImage imageNamed:@"popuptab1j.png"] forState:UIControlStateNormal];
    addButton.clipsToBounds=YES;
    [[cell contentView] addSubview:addButton];



    -(IBAction)tab1Action:(UIButton *)sender
    { 
        NSLog(@"=== >  %d",sender.tag);
    //apple your Logic
    }

注意: -使用 [[cell contentView] addSubview:addButton];而不是使用 [cell addSubview:addButton];,并且您没有为 iPhone 400 设置正确的按钮框架,或者屏幕宽度。

于 2013-07-17T06:42:39.627 回答