简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM