我已经尝试了其他类似标题问题中的所有建议。我的情况似乎很特殊。这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if ([menu_List count] == 0){
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSString *newString = [[MainMenuArray objectAtIndex:indexPath.row] stringByReplacingOccurrencesOfString:@" " withString:@""];
UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", newString,@".png"]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image1];
[imageView setFrame:CGRectMake(5.0, 1.0, 41.0, 41.0)];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[cell addSubview:imageView];
cell.textLabel.textColor = [UIColor whiteColor];
GetData *GD = [[GetData alloc] init];
cell.backgroundColor = [GD colorWithHexString:@"18204a"];
cell.textLabel.text = [NSString stringWithFormat:@"%@", [MainMenuArray objectAtIndex:indexPath.row]];
}else{
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", [menu_List objectAtIndex:indexPath.row]];
cell.textLabel.textColor = [UIColor whiteColor];
GetData *GD = [[GetData alloc] init];
cell.backgroundColor = [GD colorWithHexString:@"18204a"];
}
return cell;
}
所以字符串名称是正确的,并且大小写匹配。我已经检查了我的build设置,并且图像在复制包资源中。全部显示在模拟器中。七个中只有两个出现在列表中。如果我改变它们出现的顺序,它仍然是显示的两个图像。它们都出现在模拟器中。我正在使用 ECSlidingViewController 创建菜单,我希望显示图像。知道是什么原因造成的吗?
最佳答案
清理您的项目并检查大写字母。模拟器不区分大小写,但如果您在代码中使用“myimage.png”但您的图像名称是 MyImage.png,则真实设备不会加载图像
关于ios - UIImage 显示在模拟器上,而不是在真实设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027420/