由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFString nric]:
当我使用刚刚实现的搜索栏时,我收到此错误。有些字母可以工作,而另一些字母则会因标题中的错误而崩溃。错误似乎就在这里,但我无法弄清楚它出了什么问题:“cell.textLabel.text = info.nric;”。
有人请帮忙=(
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if(searching){
PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
else {
//First get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Patients"];
PatientInfo *info = [array objectAtIndex:indexPath.row];
// NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
return cell;
}
I get this error when i play with the searchbar that I have just implemented.. Some letters work while others will crash with the error in the title. The error seems to be here but i cannot figure out what is wrong with it : "cell.textLabel.text = info.nric;".
Someone please help =(
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if(searching){
PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
else {
//First get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Patients"];
PatientInfo *info = [array objectAtIndex:indexPath.row];
// NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
return cell;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您认为只包含
PatientInfo
对象的数组之一实际上包含一个 NSString。因此,当您编写info.nric
时,它会向 NSString 询问其nric
属性,而该属性当然不存在。实际的错误将出现在您错误地将字符串放入数组的任何位置(copyListOfItems
或listOfItems
)。One of the arrays that you think contains only
PatientInfo
objects actually contains an NSString. So when you then writeinfo.nric
, it's asking that NSString for itsnric
property, which of course doesn't exist. The actual error would be wherever you're mistakenly putting a string in the array (eithercopyListOfItems
orlistOfItems
).替换成下面的代码,你就会知道你的代码到底出了什么问题:
Replace with the following code, you will know what exactly is going wrong in your code: