iOS 5:在UITableView委托方法内部执行if语句



我目前正在编写一个应用程序,该应用程序旨在利用从后端引入的数据进行扩展。为了测试这种可伸缩性,我目前正在使用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"已经从属性列表中传递了适当的2D Array数据(使用控制台进行检查)。

同样,日志没有显示"Male"/"Female"调试消息,因此出于某种原因,这些"if"语句被跳过。有什么建议吗?

谢谢!

使用[gender isEqualToString:@"Male"]而不是==

最新更新