0

我正在创建一个自定义 UITableViewCell 视图。我有一个方法,UITableViewCell并且我以UILabel memberLabel编程方式创建了:

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

static NSString * const cellIdentifier = @"cellMemberId";

CPNMemberCell *cell = (CPNMemberCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell) {

    [[NSBundle mainBundle] loadNibNamed:@"TeamCell" owner:self options:nil];
    cell = baseCell;
}

memberLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 19, 183, 27)];
[cell addSubview:memberLabel];

NSString * const test = @"test input";
memberLabel.text = test;

  return cell;
}

所以这段代码工作得很好。但是当我在 MutableDictionary 中将测试字符串值更改为包含 JSON 响应的字符串时,一切都失败了。我专门将该字符串输出到控制台日志,以确保它不为空或其他。在将该字符串分配给 UILabel 期间,我有一个例外:

NSString * const test = [members valueForKey:@"modelId"];
NSLog(@"Output: %@", test);
memberLabel.text = test;

我不明白出了什么问题:响应正确打印到控制台,UILabel正确显示文本字符串,如第一个代码块中一样,但是当我尝试使用该响应显示字符串时,我SIGABRTmain.

4

1 回答 1

2

检查test变量的数据类型是什么。采用:

NSLog(@"data type = %@", [[test class] description]);

是印刷data type = NSString吗?如果不是,那就是问题所在。

也试试这个,

NSString* test = [ _members valueForKey:@"modelId"];
NSLog(@"Testing response in the console: %@", test);
if ([test isKindOfClass:[NSString class]]) {
  memberLabel.text = test;
} else {
  NSLog(@"test is not a string"); 
}
于 2012-11-13T00:51:33.243 回答