アドレス帳の連絡先をインポートし、画像、連絡先名、チェックボックスを表示するテーブルがあります。セルを画像、ラベル、およびチェックマークとして機能するボタンでカスタマイズしました。すべての連絡先を正常に表示でき、チェックマークも個々のセルで正常に機能しますが、テーブル内のすべてのボタンを選択状態にし、もう一度クリックするとすべての選択が解除されるすべてのボタンを選択する機能の実装に問題があります。これは私がこれまで行ってきたことです。
//これはカスタム セルのクラスです
#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
//これは FriendListViewController のテーブルビュー表示コードです
- (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 < 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;
}
//これは、テーブルビューのすべてのボタンにチェックマークを付ける必要がある私のすべての選択ボタンです
- (IBAction)selectAll:(UIButton *)sender {
//This is where I need to implement the code
}
ここでスタック オーバーフローに同様の質問があります UITableView のすべて選択ボタンを作成し、iOS の配列に選択を追加する必要があります
しかし、ここではチェックマークボタンが tableview メソッド内に作成されています。私のケースは異なり、そのコードを実装できません。これを行うより良い方法はありますか?私はストーリーボードと xcode 5 を使用しており、ios 5 以降で動作するはずです。