我试图在 UITableViewCell 的 cellAtRowIndexPath - 方法中设置数组值,但它给出了异常
[NSCFType objectAtIndex:]: unrecognized selector sent to instance 0x445e980' 2011-05-26 13:34:12.812 addressBook[2603:20b] Stack: ( 9180251,
“people”数组中的值的类型为“NSCF”。我想,它必须转换为 NSString。如何在 tableviewcell 中显示“people”数组的值?这是我的代码:
- (void)viewDidLoad { [super viewDidLoad]; ABAddressBookRef addressBook = ABAddressBookCreate(); people = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSLog(@"people....%@",people ); // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell... cell.text = [people objectAtIndex:indexPath.row]; return cell; }
最佳答案
people
数组是 ABPerson
对象的数组,而不是字符串。所以你不能将它分配为字符串。在将记录分配给单元格的 textLabel
之前,您必须处理记录并获取名称。
ABRecordRef person = (ABRecordRef)[contacts objectAtIndex:0];
CFStringRef nameString = ABRecordCopyCompositeName(person);
cell.textLabel.text = (NSString*)nameString;
CFRelease(nameString);
关于iphone - UITableViewCell 中的 NSCF 类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135624/