我有暗恋问题。这是我在网上找不到解决方案的第一件事。如果您之前遇到过同样的问题,请提供帮助。谢谢。
错误信息:
*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSNull 长度]:无法识别的选择器发送到实例 0x3a072a70”
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *lblCategoryName;
UILabel *lblGroupName;
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
lblCategoryName = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 280, 20)];
[lblCategoryName setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]];
[lblCategoryName setTag:1];
[cell.contentView addSubview:lblCategoryName];
lblGroupName = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 280, 20)];
[lblGroupName setFont:[UIFont fontWithName:@"HelveticaNeue-Italic" size:10]];
[lblGroupName setTag:2];
[cell.contentView addSubview:lblGroupName];
}
POCategory *category = [self.variantCategories objectAtIndex:indexPath.row];
lblCategoryName = (UILabel*)[cell.contentView viewWithTag:1];
[lblCategoryName setText:category.CategoryName];
lblGroupName = (UILabel*)[cell.contentView viewWithTag:2];
[lblGroupName setText:category.GroupName];
return cell;
}
奇怪的是;当我注释掉以下行或当我的数组“variant.Categories”为空时,它工作得很好。(我什至可以从其他函数填充表格视图)但是它并没有在这些行中被粉碎。我可以在调试时看到对象。它不是空的。一切看起来都很正常。
//POCategory *category = [self.variantCategories objectAtIndex:indexPath.row];
//lblCategoryName = (UILabel*)[cell.contentView viewWithTag:1];
//[lblCategoryName setText:category.CategoryName];
//lblGroupName = (UILabel*)[cell.contentView viewWithTag:2];
//[lblGroupName setText:category.GroupName];
“variantCategories”数组在我的 UITableViewController 类中是这样定义的,这是我传递给这个视图控制器的唯一变量。
@property (nonatomic, retain) NSArray *variantCategories;
我试图让它“强大”而不是“保留”,但它没有奏效。
任何形式的帮助都非常感谢。
谢谢。