2011-12-15 24 views
0
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值作爲像下面進入 -[NSCFString objectAtIndex:]:無法識別選擇使用nsmutabledictionery

(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

您是否使myCallLogDict的屬性在appappDelegate中合成? – Maulik 2011-12-15 04:53:26

+0

是的,我在應用程序代理 – user198725878 2011-12-15 04:54:20

回答

1

我想你必須將你的密鑰數據保存在一個數組中,然後在該數組上使用objectAtIndex

1

您期待您的字典包含關鍵字CallLogTimeStampKey的字符串數組,但您只插入了一個字符串。

3

試試這個:

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

你不需要通過

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

使用objectAtIndex爲你所得到的單串在我的情況有以下問題:

  1. 有一個屬性@property (nonatomic, retain) NSIndexPath *selectedCell;
  2. 其中synthezid ED作爲@synthesize selectedCell = _selectedCell;
  3. 與吸氣

    • (NSIndexPath *)selectedCell { 如果{ _selectedCell = [NSIndexPath indexPathForRow:self.selectedImageNumber切入口:kTexturesListSection](_selectedCell!); } return _selectedCell; }
  4. ,然後在代碼中的一些在呼叫self.selectedCell.row造成死機

吸氣已被更改爲

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

一個錯誤消失了。該錯誤僅在iOS 5上有所體現。

相關問題