7

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.

Dennis
  • 362
  • 4
  • 13
  • Uhm, isn't this code working or what? –  Jan 29 '13 at 20:55
  • Static tableViews are just that, static. You have to set it up in Storyboard. You can't run code on them because they're static. So you don't get access to a dynamic datasource where you could run this code. – Ryan Poolos Jan 29 '13 at 20:56

2 Answers2

19

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.

migrant
  • 498
  • 5
  • 14
  • There is something I don't understand: I did like you suggested, except I need an `UIImageView`, and I see the `_customAccessoryView` which is my `UIImageView`, but I can't access it. So how then? – nightfixed May 22 '15 at 10:36
0

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

tkanzakic
  • 5,499
  • 16
  • 34
  • 41