1

これはちょうど私を狂わせようとしています。単純なグループ化されたテーブルを作成しようとしていますが、実行するたびに次のエラーが発生します。

-[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x489c

行をスローしているコードは次のとおりです(正確な行をアスタリスクで囲んでいます)。

-(UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *newSpecCell = @"newSpecCell";
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [segmentArray objectAtIndex:section];
NSArray *names = [specsDictionary objectForKey:key];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:newSpecCell];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:newSpecCell];
}

cell.textLabel.text = [names objectAtIndex:row]; // <---
return cell;

}

私のロジックobjectAtIndexから、配列からを要求していますが、エラーはそれを定数文字列に送信していることを示しています。

私はいくつかのことを試しました(文字列を作成するなど[names objectAtIndex:row]、違いはないようです。また、NSLogを使用して値を表示すると、names正しく表示されるため、配列に必要な値が含まれていることがわかります。

4

1 に答える 1

0

配列が正しく設定されていないという単純な問題。マディのおかげで、私はそれをすぐに理解しました。

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *newSpecCell = @"newSpecCell";
 NSUInteger section = [indexPath section];
 // NSUInteger row = [indexPath row];
 NSString *key = [segmentArray objectAtIndex:section];
 // NSArray *names = [specsDictionary objectForKey:key];
 NSString *values = [specsDictionary objectForKey:key]; //<--
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:newSpecCell];
 if (cell == nil) {
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                              reuseIdentifier:newSpecCell];
}

cell.textLabel.text = values; //<--
return cell;
}

コメントされた行を削除し、示されているようにcell.textlabel.textを変更しただけで、すべてうまくいきました。

于 2012-10-22T01:46:41.357 に答える