Need to create a select all button for UITableView and add selections to an array in iOS

后端 未结 3 576
时光取名叫无心
时光取名叫无心 2021-01-23 16:49

I have a UITableViewController that shows a list of items from NSMutableArray, along with a button that serves as a check box that the user can select/deselect. I am able to su

3条回答
  •  花落未央
    2021-01-23 17:47

    Here i m Posting Another Answer so that it might help to others who wants to make this from Scratch and remove any Confusions.

    Instead of Adding Button to tableViewCell ,you can use ImageView as AccessoryView.

    UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease];
    imageView1.tag = indexpath.row;
    
    [cell.accessoryView addSubview:imageView1];
    

    And later get subview using -viewWithTag: method:

    UIImageView *getImageView1 = (UIImageView*)[cell.accessoryView viewWithTag:rowNumber];
    getImageView1.image=[UIImage ImageNamed:@"checked.png"];
    

    By the Above code we can change the image of imageView in selectRowAtindexPath

    From my first Answer you can use the code to Select all or Multiple cell of tableView.

提交回复
热议问题