0

このエラーが発生し続けます:

2013-03-30 19:48:40.029 try[14838:907] -[__NSSetM objectAtIndex:]: 認識されないセレクターがインスタンス 0x1e8ea660 に送信されました 2013-03-30 19:48:40.030 try[14838:907] * によるアプリの終了uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSetM objectAtIndex:]: unrecognized selector sent to instance 0x1e8ea660' * First throw call stack: (0x33e523e7 0x3bb43963 0x33e55f31 0x33e5464d 0x33dac208 0xe5bc7 0x35cac569 0x35c91391 0x35ca8827 0x35c648c7 0x35a10513 0x35a100b5 0x35a10fd9 0x35a109c3 0x35a107d5 0x35a10639 0x33e27941 0x33e25c39 0x33e25f93 0x33d9923d libc++abi.dylib: 例外をスローして呼び出された終了 (lldb)

// ここに私のコードがあります:

- (void)fetchTweets
{

    UIApplication* app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = YES;


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL:
                        [NSURL URLWithString: @"***.json"]];

        NSError* error;



        tweets = [NSJSONSerialization JSONObjectWithData:data
                                                 options:kNilOptions
                                                   error:&error];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    });
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tweets.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"showVideo";

    CustomVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(!cell)
    {
        cell = [[CustomVideoCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 277, 58)];
    av.backgroundColor = [UIColor clearColor];
    av.opaque = NO;
    av.image = [UIImage imageNamed:@"cell_bg.png"];
    cell.backgroundView = av;


    UIImage *image = [UIImage   imageNamed:@"disclosure_arrow_white.png"];
    UIImageView *av2 = [[UIImageView alloc] initWithFrame:CGRectMake(44.0, 44.0, image.size.width, image.size.height)];
    av2.backgroundColor = [UIColor clearColor];
    av2.opaque = NO;
    av2.image = [UIImage imageNamed:@"disclosure_arrow_white.png"];
    cell.accessoryView = av2;



    NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];


    cell.title.text = [tweet objectForKey:@"title"];


    NSLog(@"t: %@",[tweet objectForKey:@"title"]);


    return cell;

}
4

2 に答える 2

0

行の後:

CustomVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

セルに実際に値があることを確認し、ない場合は新しいセルを作成する必要があります。

CustomVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
  cell = [[CustomVideoCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier];
}

幸運を!

新しいエラーの更新:

JSONObjectWithData の結果の「つぶやき」変数は、NSArray ではなく NSDictionary です。NSDictionary は「objectAtIndex」を実装していないため、認識されないセレクター例外がスローされます。通常、つぶやきディクショナリには、つぶやきの配列を含む特定のキーが必要です。このキーは、fetchTweets メソッドの「つぶやき」変数に割り当てる必要があります。

私が言及していることの多くについてよくわからない場合は、Sensible TableView フレームワークを使用することを強くお勧めします。フレームワークは、すべての Web サービス ツイートを自動的に取得し、それらをテーブル ビューに自動的に表示することができます。私は個人的に常にそれを使用しており、手作業を大幅に節約しています。

于 2013-03-30T23:29:53.380 に答える