当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Displaying UIImage Programatically in a Table Cell

问题描述:

I am working with some modified sample code and trying to make use of my customized storyboard cell (just an image view and 2 text labels) so that I can easily customize the cell in storyboard as needed.

My arrays are pretty simple:

teams = [NSArray arrayWithObjects:@"Team1", @"Team2", nil];

embed = [NSArray arrayWithObjects:@"77.png", @"777.png", nil];

The code that follows all works great, with the exception of the UIImage code - which I can't seem to figure out.

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

{

static NSString *simpleTableIdentifier = @"TeamCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];

}

UIImageView *myimage = (UIImageView *)[cell viewWithTag:100];

myimage.image = [embed objectAtIndex:indexPath.row];

UILabel *teamLabel = (UILabel *)[cell viewWithTag:101];

teamLabel.text = [teams objectAtIndex:indexPath.row];

return cell;

}

The code for the teamlabel works great and I am able to pass that along on a segue controller, but I have a serious issue with the UIImage Code. Any ideas what I am goofing up?

Thanks in advance for any help.

网友答案:

By setting the image name will not work. Create an object of UIImage by below way.

myimage.image = [UIImage imageNamed:[embed objectAtIndex:indexPath.row]];
网友答案:

You should use some code like this:

myimage.image = [UIImage imageNamed:[embed objectAtIndex:indexPath.row]];

That should do the trick.

Hope it helps

网友答案:

You have to use UIImages imageNamed: method.

myimage.image = [UIImage imageNamed:[embed objectAtIndex:indexPath.row]];

You are currently assigning an NSString instead of a UIImage to your imageView.

分享给朋友:
您可能感兴趣的文章:
随机阅读: