Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading UIImageView into UITableViewCell Accessory View

I have an jpg image named Check Mark.jpg that I'm trying to load into the accessory view of a table view cell. This is what my code currently is:

cell.accessoryView = 
          [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Check Mark.jpg"]];

in the cellForRowAtIndexPath method

When I do this, nothing displays in the table view cell. I have checked the name of the file, and have tried putting it in the folder containing the .xcodeproj file and the folder containing all the code files. Neither of these have worked. I also tried declaring the UIImageView and UIImage as strong properties and initializing them in the init: method. None of this works. I can display the detail disclosure button in the view, so I know the accessory view is there, but I can't seem to figure out how to display this simple image.

Do I have to somehow load the image into my project?

like image 230
Iowa15 Avatar asked Aug 13 '13 03:08

Iowa15


1 Answers

After setting the image up try to set the frame next.

Something like this:

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

I think the accessoryView frame is set to 0.

like image 186
Joshua Avatar answered Nov 02 '22 17:11

Joshua