Dennis
Dennis

Reputation: 400

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.

Upvotes: 7

Views: 3811

Answers (2)

migrant
migrant

Reputation: 508

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.

Upvotes: 19

tkanzakic
tkanzakic

Reputation: 5499

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

Upvotes: 0

Related Questions