私は、ユーザーの連絡先リストと提案された連絡先を表示するアプリを作っています。私は提案された連絡先セクションのチェックボックスをこのようにあらかじめ選択しておきたい。誰も私を助ける?ビューの前にいくつかのUIButtonsをあらかじめ選択してください
今のところ、私はどのようにこれを実装するには考えています。試してみると、すべてのチェックボックスがあらかじめ選択されています。ここ
はcellforRowIndexPath
ここ-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
AddressBookCell *cell = nil;
if([tableView isEqual:self.myTableView]){
if([indexPaths objectForKey:indexPath]){
cell = [indexPaths objectForKey:indexPath];
}else{
if([letterArray objectAtIndex:indexPath.section]){
static NSString *TableViewIdentifier = @"MyCells";
cell = [[AddressBookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text=[[[letterArray objectAtIndex:indexPath.section] objectAtIndex:0] valueForKey:@"name"];
[[letterArray objectAtIndex:indexPath.section] removeObjectAtIndex:0];
cell.checkbox.tag = indexPath.row;
[cell.checkbox addTarget:self action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
}
}
[indexPaths setObject:cell forKey:indexPath];
}
return cell;
}
のための私のコードは、あなたのif([letterArray objectAtIndex:indexPath.section])
文の終わりに私のletterArray
-(void)setUpContacts{
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
eventController = [[UOEventDetailController alloc]init];
[tempArray addObject:[eventController comparingArrays]];
NSDictionary *alphabet = [[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:1],@"A",[NSNumber numberWithInt:2],@"B",[NSNumber numberWithInt:3],@"C",[NSNumber numberWithInt:4],@"D",[NSNumber numberWithInt:5],@"E",[NSNumber numberWithInt:6],@"F",[NSNumber numberWithInt:7],@"G",[NSNumber numberWithInt:8],@"H",[NSNumber numberWithInt:9],@"I",[NSNumber numberWithInt:10],@"J",[NSNumber numberWithInt:11],@"K",[NSNumber numberWithInt:12],@"L",[NSNumber numberWithInt:13],@"M",[NSNumber numberWithInt:14],@"N",[NSNumber numberWithInt:15],@"O",[NSNumber numberWithInt:16],@"P",[NSNumber numberWithInt:17],@"Q",[NSNumber numberWithInt:18],@"R",[NSNumber numberWithInt:19],@"S",[NSNumber numberWithInt:20],@"T",[NSNumber numberWithInt:21],@"U",[NSNumber numberWithInt:22],@"V",[NSNumber numberWithInt:23],@"W",[NSNumber numberWithInt:24],@"X",[NSNumber numberWithInt:25],@"Y",[NSNumber numberWithInt:26],@"Z", nil];
for(int i = 1; i<=27; i++){
[tempArray addObject:[NSNull null]];
}
Contacts *contact = [[Contacts alloc]init];
contactNumbers = [contact phoneNumbers];
for (NSDictionary* info in contactNumbers) {
firstLetter = [info objectForKey:@"lastName"];
int index = 27;
if([firstLetter length] > 0){
firstLetter =[NSString stringWithFormat:@"%C",[firstLetter characterAtIndex:0]];
firstLetter= [firstLetter capitalizedString];
if([alphabet objectForKey:firstLetter]){
NSNumber *t = [alphabet valueForKey:firstLetter];
index = [t intValue];
}
}
if([tempArray objectAtIndex:index] == [NSNull null]){
[tempArray insertObject:[NSMutableArray array] atIndex:index];
}
[[tempArray objectAtIndex:index] addObject:info];
}
[alphabet release];
NSArray *alphabet2 = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
NSMutableArray *tempArray2 = [[NSMutableArray alloc]init];
NSMutableArray *titleTemp = [[NSMutableArray alloc]init];
int c = 0;
for(int i = 0; i<=27; i++){
if([tempArray objectAtIndex:i] != [NSNull null]){
if(i == 0){
[titleTemp insertObject:@"Suggested" atIndex:c];
}else if(i == 27){
[titleTemp insertObject:@"Others" atIndex:c];
}else{
int loc = i -1;
[titleTemp insertObject:[alphabet2 objectAtIndex:loc] atIndex:c];
}
[tempArray2 insertObject:[tempArray objectAtIndex:i] atIndex:c];
c++;
}
}
[alphabet2 release];
[tempArray release];
letterArray = tempArray2;
titlePointer = titleTemp;
}
いくつかのボタンをあらかじめ選択しておきたいので、ビューをロードするときに押してください。提案されたセクションはすでにあらかじめ用意されています –