2

私はときめきの問題を抱えています。これは、オンラインで解決策を見つけることができなかった最初のことです。以前に同じ問題が発生した場合は、助けてください。ありがとう。

エラーメッセージ:

*キャッチされない例外 '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;

「保持」ではなく「強力」にしようとしましたが、うまくいきませんでした。

どんな種類の助けでも大歓迎です。

ありがとう。

4

2 に答える 2

1

このメッセージは、lengthメソッドが NSNull オブジェクトで呼び出されたことを示しています。length メソッドは で呼び出される可能性が最も高くNSString、2 行にコメントするとsetText問題が解決されるため、おそらく GroupName または CategoryName のいずれかがNSNull. これら 2 つのプロパティが Category オブジェクトで strong として定義されていることを確認する必要があります。

于 2014-04-09T21:40:47.110 に答える
0

このコードを確認できますか?

if (cell==nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strIndentifier]; countryLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,CGRectGetWidth(tableView.bounds)/2, 44)]; countryLbl.textColor = [UIColor blueColor]; countryLbl.textAlignment = NSTextAlignmentLeft; [cell.contentView addSubview:countryLbl]; [countryLbl setTag:11]; localNoLbl = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(tableView.bounds)/2, 0,CGRectGetWidth(tableView.bounds)/2, 44)]; localNoLbl.textColor = [UIColor blackColor]; localNoLbl.textAlignment = NSTextAlignmentCenter; [cell.contentView addSubview:localNoLbl]; [localNoLbl setTag:12];

    }

    [cell.contentView.subviews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {


        if ([obj isKindOfClass:[UILabel class]]) {
           countryLbl = (UILabel *)[cell.contentView viewWithTag:11];

                countryLbl.text = [countryLocArray objectAtIndex:indexPath.row];
            localNoLbl = (UILabel *)[cell.contentView viewWithTag:12];
                localNoLbl.text=[locArray objectAtIndex:indexPath.row];

            NSLog(@"%@---%@-%@-%@",locArray,countryLocArray,countryLbl.text,localNoLbl.text);
    }
    }];
于 2015-10-06T04:38:49.800 に答える