Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Accessoryview to static UITableViewCell?

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.

like image 460
Dennis Avatar asked Jan 29 '13 20:01

Dennis


1 Answers

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.

like image 140
migrant Avatar answered Oct 28 '22 03:10

migrant