I have created a UITableViewController with a UITableView and static UITableViewCells.

How can I change the Accessory View to a custom Image within a UIImageView?

I know how to change the Accessory View generally:

UIImage *accessor = [UIImage imageNamed:@"imageName"];
[somecell setAccessoryView:[[UIImageView alloc] initWithImage: accessor]];

The solution:

Create an IBOutlet for each UITableViewCell which should have a custom accessory view and connect the IBOutlet to the UITableViewCell in the storyboard. After that you can set the accessory view like above.

有帮助吗?

解决方案

I found a better solution:

  1. Drag a view (for example a instance of UISwitch) into UITableViewController in storyboard

    enter image description here

  2. Selet the cell on which you want to add a custom accessory view. Then open the Connections inspector, drag the accessoryView in section Outlets to the view that you created in step 1.

    enter image description here

  3. Now run the app, see a custom accessory view appearing in a static UITableViewCell. Of course you can create another IBOutlet between the UISwitch and controller so that you could get the reference of it, or create an IBAction for receiving action when user change the value of UISwitch.

其他提示

Add a custom UIButton in the storyboard and set the image you want to it

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top