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

use*_*261 1 iphone if-statement uitableview ios5

我目前正在编写一个应用程序,它可以扩展后端引入的数据.为了测试这种可伸缩性,我目前正在使用plists来引入一些基本数据.

为了性别/视觉目的(目前使用颜色),计划最终会在用户名旁边显示男/女图标,但是,在正确的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;
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,userArray和gender都是已经初始化的实例变量."userArray"已经从属性列表中传递了相应的2D Array数据(使用控制台来检查).

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

谢谢!

wat*_*n12 5

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