私はときめきの問題を抱えています。これは、オンラインで解決策を見つけることができなかった最初のことです。以前に同じ問題が発生した場合は、助けてください。ありがとう。
エラーメッセージ:
*キャッチされない例外 '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;
「保持」ではなく「強力」にしようとしましたが、うまくいきませんでした。
どんな種類の助けでも大歓迎です。
ありがとう。