我正在制作一个显示用户联系人列表和建议联系人的应用程序。我希望像这样预先选择建议的联系人部分的复选框。有人帮我吗?
![1]: http://min.us/mOhamWjnd
到目前为止,我不知道如何实现这一点。当我尝试时,所有复选框都被预先选中。
这是我的 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;
}
这是我的 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;
}