开发者

NSCF type value into UITableViewCell

I'm trying to set array values in UITableViewCell at cellAtRowIndexPath - method, but it's giving the exception

[NSCFType objectAtIndex:]: unrecognized selector sent to instance 0x445e980'
2011-05-26 13:34:12.812 addressBook[2603:20b] Stack: (
    9180251,

the values in 'people' array is of type 'NSCF'. I guess, it have to convert in to NSString. how will I show the vaues of 'people' array in tableviewcell? here is my code:

开发者_StackOverflow社区

- (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 array is an array of ABPerson objects and not strings. So you can't assign it to as a string. You will have to process the record and get the name before assigning it to cell's textLabel.

ABRecordRef person = (ABRecordRef)[contacts objectAtIndex:0];
CFStringRef nameString = ABRecordCopyCompositeName(person);
cell.textLabel.text = (NSString*)nameString;
CFRelease(nameString);


objectAtIndex: is NSArray instance method which you are calling at NSString (address)

EDIT: If you are sure people contains NSArray or a subclass of it, then do its enumeration and not NSString. You cannot use instance method of NSArray class for NSString instances. Hence, it is not recognized.


Address is a string(there is no objectAtIndex: method)
Just remove for loop, use :

cell.text = [people objectAtIndex:indexPath.row];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜