3
votes

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:


- (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;
}

3
can you give the structure of object you have in address array?Vaibhav Tekam
Also, is adress reallly an array?Vaibhav Tekam
What is people? It doesn't seem to contain strings.Deepak Danduprolu
@deepak : people array contain people....( <NSCFType: 0x445e760>, <NSCFType: 0x445e840>, <NSCFType: 0x4460f90>, <NSCFType: 0x44610e0>, <NSCFType: 0x4461cb0> )user720235

3 Answers

2
votes

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);
0
votes

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.

0
votes

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

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