简体   繁体   中英

I have button in table view cell when I click the perticular index button state will change

- (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];

}

When I click particular index button then my button name will change and remaining cells will be select.

When I got response of button name as accept and reject then only my table view cells will be select.

Try this

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

May be :

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM