是的,在uitableview中没有设置图像

时间:2015-03-26 05:14:03

标签: ios objective-c uitableview

我想运行代码,因为当代码为true时,应显示正确的图像,当它为false时,它应显示错误的符号。 例如,牛肉干,切碎和成形应显示正确的图像 数据应该从数据库中获取

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if (tableView == self.searchDisplayController.searchResultsTableView)
{
    cell.textLabel.text = [searchResult objectAtIndex:indexPath.row];
    int random = arc4random() % arrimg.count;
    cell.imageView.image = [UIImage imageNamed:[arrimg objectAtIndex:random]];
    cell.accessoryType = UITableViewCellAccessoryNone;

    [cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];

} else {
    cell.textLabel.text = [arrname objectAtIndex:indexPath.row];
    int random = arc4random() % arrimg.count;
    cell.imageView.image = [UIImage imageNamed:[arrimg objectAtIndex:random]];

    cell.accessoryType = UITableViewCellAccessoryNone;
     //        cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Yes_check.png"]];
     //        [cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];
}
cell.backgroundColor = [UIColor colorWithRed:99.0/255 green:170.0/255 blue:229.0/255 alpha:1.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font=[UIFont fontWithName:@"Marker Felt" size:15];

return cell;
 }

1 个答案:

答案 0 :(得分:-1)

请制作以下步骤:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
if([checkmarkArray[indexPath.row] isEqualToString:@"NO"]) // Wrong image displayed here
{
 cell.accessoryType = UITableViewCellAccessoryNone;

    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wrongImage.png"]];
    [cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];

}
else
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"trueImage.png"]];
    [cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];
}

}
相关问题