iphone - UITableViewCell 中的 NSCF 类型值

标签 iphone

我试图在 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/

相关文章:

iphone - 如何应用正则表达式和/或清理电话线?

iphone - UIAlertView 按钮到另一个 View Controller

iphone - 如何从 iPhone 应用程序中删除 UIApplicationMain?

iPad 上的 iOS 应用仅适用于部分屏幕

ios - 如何解决此Mach-O Linker问题?

ios - 在UIView类别中创建UIBezierPath。没有显示

iphone - 在 iPhone 应用程序中存储密码

android - flash air mobile 上鼠标事件和触摸事件的响应缓慢和延迟时间

iphone - 聊天应用程序中的 "stalker status"是什么意思?

iphone - 从扩展调用 UIViewController 中的函数