tahir
tahir

Reputation: 1026

UITableViewController and sub views

I have a screen where I want to display the details of some product. I'm using storyboards.

I have done this using a tableview with static cells, but static cells can only be done within a tableview of UITableViewController. And the problematic point is that I also want to have a Imageview within this controller. this is not possible as the tableview of a UITableViewController take all the screen size.

So I'm doing the Imageview as a subview of the tableview.

I'm wondering if it is the right way to do it, there are similar issues on stackoverflow but none is corresponding to my use case (storyboard + tableviewcontroller + staticcell + sub view)

Upvotes: 1

Views: 192

Answers (3)

benzado
benzado

Reputation: 84388

Without writing any custom code, you could either:

  1. Put a UIImageView in the table view's header or footer view.
  2. Create a static cell and put the UIImageView in that. Table cells don't have to be uniform length, you could make it taller than the other cells if needed.

Upvotes: 1

Mateusz
Mateusz

Reputation: 314

You can have your subclass of UITableViewController. After you initialize it take its view (tableView) and add it as subview to some other view controller. This way you can set the frame of tableView to occupy the bottom of the (top containing) view controller. To the same view controller you can add additional subviews like UIImageView and position it on the top. The only problems you will encounter might be related to missing notifications to your UITableViewController subclass (viewWillDisappear, viewDidDissappear, viewWillAppear, viewDidAppear, ...). But you can forward them to from your top view controller. Or you could use methods from iOS 5 to add subclass of UITableViewController as a child view controller and position it as you wish. But this is useful if you plan on supporting devices with iOS 5.0+.

See documentation of method in UIViewController:

- (void)addChildViewController:(UIViewController *)childController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

Upvotes: 1

BabyPanda
BabyPanda

Reputation: 1592

  • Use a UITableView as a property of the viewController and add it to vc.view, rather than subclass a UITableViewController, then set its frame as you like
  • Add the imageView to vc. If you need to put it on top of the UITableView, for example, add it as the TableView's header.

Upvotes: 0

Related Questions