By setting the image name will not work. Create an object of UIImage by below way.
myimage.image = [UIImage imageNamed:[embed objectAtIndex:indexPath.row]];
سؤال
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 UIImage
s imageNamed:
method.
myimage.image = [UIImage imageNamed:[embed objectAtIndex:indexPath.row]];
You are currently assigning an NSString
instead of a UIImage
to your imageView.