【发布时间】:2016-11-10 07:00:13
【问题描述】:
我有一本包含以下详细信息的字典
{
Name = "American Airlines";
Picture = (
""
);
Rate = 3;
},
我想在单元格标签上显示名称...为此我正在执行以下代码:
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getDetail:) name:@"NewNotification" object:nil];
}
-(void)getDetail:(NSNotification *)notification
{
if([notification.name isEqualToString:@"NewNotification"])
{
NSDictionary *dictionary=notification.userInfo;
NSLog(@"Dictionary %@",dictionary);
userInfo=dictionary;
[self.listView reloadData];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//return [userInfo count];
return 115;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"cell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell== nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.Name.text =[userInfo valueForKey:@"Name"];
NSLog(@"the cell.Name.text is %@",cell.Name.text);
//[cell updateCell:userInfo];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75;
}
我无法理解我在代码中做错了什么,因为它崩溃并且标签上没有显示任何内容。它给出了异常
“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__NSArrayI 长度]:无法识别的选择器发送到实例0x7bea2d20'”
请检查代码并告诉我哪里出错了!
【问题讨论】:
-
添加异常断点,看看它在哪里崩溃。
-
要了解如何添加异常断点,您可以查看stackoverflow.com/questions/17802662/…。这很容易做到。
标签: ios dictionary custom-cell