user198725878
user198725878

Reputation: 6386

[NSCFString objectAtIndex:]: unrecognized selector sent to instance when using nsmutabledictionery

NSDateFormatter *formatter;
    NSString *dateString;
    formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd-MM-yyyy HH:mm a"];
    dateString = [formatter stringFromDate:[NSDate date]];
    [formatter release];

    appDelegate.myCallLogDict = [[NSMutableDictionary alloc]init];
    [appDelegate.myCallLogDict setObject:phoneNo forKey:@"CallLogPhoneNoKey"];
    [appDelegate.myCallLogDict setObject:dateString forKey:@"CallLogTimeStampKey"];

I have stored phone no and time into an nsmutabledictionery and i want to access that dictionery value as like below into the -

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method

cell.detailTextLabel.text = [[appDelegate.myCallLogDict objectForKey:@"CallLogTimeStampKey" ]objectAtIndex:row];
cell.textLabel.text = [[appDelegate.myCallLogDict objectForKey:@"CallLogPhoneNoKey"] objectAtIndex:row];

when i run the above code i get the below error

Please help me up

-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5b227e0
2011-12-15 10:06:09.050 MyDialer[1090:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5b227e0'

Thanks a lot for your help

Upvotes: 0

Views: 4029

Answers (4)

dmi3j
dmi3j

Reputation: 51

In my case there was the following problem:

  1. there is a property @property (nonatomic, retain) NSIndexPath *selectedCell;
  2. which synthezided as @synthesize selectedCell = _selectedCell;
  3. with a getter

    • (NSIndexPath *)selectedCell { if (!_selectedCell) { _selectedCell = [NSIndexPath indexPathForRow:self.selectedImageNumber inSection:kTexturesListSection]; } return _selectedCell; }
  4. and then some where in the code the call self.selectedCell.row caused crash

After getter has been changed to

  • (NSIndexPath *)selectedCell { if (!_selectedCell) { _selectedCell = [[NSIndexPath indexPathForRow:self.selectedImageNumber inSection:kTexturesListSection] retain]; } return _selectedCell; }

a bug disappeared. The bug has been noticed on iOS 5 only.

Upvotes: 1

Maulik
Maulik

Reputation: 19418

try this :

cell.detailTextLabel.text = [appDelegate.myCallLogDict objectForKey:@"CallLogTimeStampKey"];
cell.textLabel.text = [appDelegate.myCallLogDict objectForKey:@"CallLogPhoneNoKey"];

you don't need to use objectAtIndex as you are getting single string by

[appDelegate.myCallLogDict objectForKey:@"CallLogPhoneNoKey"];

Upvotes: 3

Ajeet Pratap Maurya
Ajeet Pratap Maurya

Reputation: 4254

I think you have to save your key data in an array and then use the objectAtIndex on that array.

Upvotes: 1

morningstar
morningstar

Reputation: 9132

You are expecting your dictionary to contain an array of strings for the key CallLogTimeStampKey, but you inserted just a single string.

Upvotes: 1

Related Questions