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"];
我已将电话号码和时间存储到nsmutabledictionery中,我想访问该dictionery值,如下所示 -
(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];
当我运行上面的代码时,我得到以下错误
请帮帮我
-[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'
非常感谢你的帮助
答案 0 :(得分:3)
试试这个:
cell.detailTextLabel.text = [appDelegate.myCallLogDict objectForKey:@"CallLogTimeStampKey"];
cell.textLabel.text = [appDelegate.myCallLogDict objectForKey:@"CallLogPhoneNoKey"];
您不需要使用objectAtIndex,因为您正在通过
获取单个字符串[appDelegate.myCallLogDict objectForKey:@"CallLogPhoneNoKey"];
答案 1 :(得分:1)
您希望您的字典包含密钥CallLogTimeStampKey的字符串数组,但您只插入了一个字符串。
答案 2 :(得分:1)
我认为您必须将关键数据保存在数组中,然后使用该数组上的objectAtIndex
。
答案 3 :(得分:1)
在我的情况下,存在以下问题:
@property (nonatomic, retain) NSIndexPath *selectedCell;
@synthesize selectedCell = _selectedCell;
带有吸气剂
然后在代码中的某些地方调用self.selectedCell.row导致崩溃
将getter更改为
一个错误消失了。该漏洞仅在iOS 5上被注意到。