Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do select all function for custom cell in UITableView in iOS
    primarykey
    data
    text
    <p>I have a table that imports the address book contacts and displays the image, contact name and a checkbox, i've customized my cell with image, label and a button which serves as a checkmark. I'm successfully able to display all contacts and the checkmark also works fine for individual cells, but i'm having trouble implementing select all functionality that will put all the button in the table in selected state and clicking it again will deselect it all. This is what I have done so far.</p> <p>//This is the class for my custom cell</p> <pre><code>#import "InviteFriendsCell.h" @implementation InviteFriendsCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } //This is my checkmark button -(IBAction)onAddTouched:(id)sender { UIButton *addButton = (UIButton *)sender; [addButton setSelected:![addButton isSelected]]; } @end </code></pre> <p>//This is my tableview display code in FriendListViewController</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"friendsCell"; InviteFriendsCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell==nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"InviteFriendsCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } // Configure the cell... NSUInteger row = 0; NSUInteger sect = indexPath.section; for (NSUInteger i = 0; i &lt; sect; ++ i) row += [self tableView:tableView numberOfRowsInSection:i]; row += indexPath.row; cell.thumbImage.layer.cornerRadius=25; cell.thumbImage.clipsToBounds=YES; cell.thumbImage.image=nil; self.persons = CFArrayGetValueAtIndex(self.contactAdd, row); NSString *tweet=[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyCompositeName(self.persons)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; [cell.friendName setText:tweet]; if (ABPersonHasImageData(persons)) { NSData *imgData = (__bridge NSData *) ABPersonCopyImageDataWithFormat(persons, kABPersonImageFormatThumbnail); cell.thumbImage.image = [UIImage imageWithData:imgData]; } else { cell.thumbImage.image = [UIImage imageNamed:@"name_icon.png"]; } return cell; } </code></pre> <p>//This is my select all button which should put checkmark to all button in tableview</p> <pre><code> - (IBAction)selectAll:(UIButton *)sender { //This is where I need to implement the code } </code></pre> <p>There is a similar question in stack overflow here <a href="https://stackoverflow.com/questions/14209145/need-to-create-a-select-all-button-for-uitableview-and-add-selections-to-an-arra">Need to create a select all button for UITableView and add selections to an array in iOS</a></p> <p>But here the checkmark button is created inside the tableview method, my case is different and I'm unable to implement that code. Is there a better way to do this? I'm using storyboard and xcode 5 and should work for ios 5 or above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload