当我单击特定索引按钮状态时,我在表视图单元格中有按钮会改变

时间:2016-03-21 05:14:17

标签: ios objective-c uitableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellClassName = @"CarDriverTableViewCell";

    CarDriverTableViewCell *cell = (CarDriverTableViewCell *)[tableView dequeueReusableCellWithIdentifier: CellClassName];

    if (cell == nil)
    {
        cell = [[CarDriverTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellClassName];
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CarDriverTableViewCell"
                                                     owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.backgroundColor=[UIColor blackColor];

    }

    UILabel *lbltime=(UILabel *)[cell viewWithTag:1];
    UILabel *lbldriver=(UILabel *)[cell viewWithTag:2];
    UILabel *lbllicence=(UILabel *)[cell viewWithTag:4];
    bookbtn=(UIButton *)[cell viewWithTag:5];
   // [bookbtn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchUpInside];

    lbltime.text=[[arrnames valueForKey:@"time"]objectAtIndex:indexPath.row];
    lbldriver.text=[[arrnames valueForKey:@"name"]objectAtIndex:indexPath.row];
    lbllicence.text=[[arrnames valueForKey:@"license_plate"]objectAtIndex:indexPath.row];

    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    bookbtn.tag=indexPath.row;
    [bookbtn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchUpInside];


}
-(void)btnclicked:(id)sender
{
    [bookbtn setTitle:@"Pending" forState:UIControlStateNormal];

}

当我点击特定的索引按钮时,我的按钮名称将会改变,剩下的单元格将被选中。

当我将按钮名称的响应作为接受和拒绝时,只会选择我的表格视图单元格。

2 个答案:

答案 0 :(得分:0)

试试这个

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    bookbtn.tag=indexPath.row;
    [bookbtn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchUpInside];
   [yourtableview realoadData];
}

答案 1 :(得分:0)

可能是:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    bookbtn.tag=indexPath.row;
    [bookbtn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchUpInside];
     return bookbtn

}