【问题标题】:iOS 5: Executing if statements inside of a UITableView delegate methodiOS 5:在 UITableView 委托方法中执行 if 语句
【发布时间】:2012-07-11 16:28:59
【问题描述】:

我目前正在编写一个应用程序,该应用程序旨在利用从后端引入的数据进行扩展。为了测试这种可扩展性,我目前正在使用 plist 来引入一些基本数据。

计划最终让男性/女性图标出现在用户名旁边以用于性别/视觉目的(目前使用颜色),但是,在正确的 tableView 方法中编写条件语句后,应用程序似乎跳过了这些参数完全。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SelectProfileCell *cell = (SelectProfileCell *) [tableView dequeueReusableCellWithIdentifier:@"SelectProfileCell"];

NSArray *array = [[NSArray alloc] initWithArray:[userArray objectAtIndex:indexPath.row]];

cell.nameLabel.text = [array objectAtIndex:0];

gender = [array objectAtIndex:1];

if(gender == @"Male"){
    cell.genderLogo.backgroundColor = [UIColor blueColor];
    NSLog(@"Male");
   }
if(gender == @"Female"){
cell.genderLogo.backgroundColor = [UIColor greenColor];
    NSLog(@"Female");
}

return cell;
}

在这种情况下,userArray 和gender 都是已经初始化的实例变量。 "userArray" 已经从属性列表中传递了适当的二维数组数据(使用控制台检查)。

同样,日志没有显示“男性”/“女性”调试消息,因此这些“if”语句由于某种原因被跳过。有什么建议吗?

谢谢!

【问题讨论】:

    标签: iphone uitableview ios5 if-statement


    【解决方案1】:

    使用 [gender isEqualToString:@"Male"] 代替 ==

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多