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)
Without writing any custom code, you could either:
Put a UIImageView in the table view's header or footer view.
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.
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);
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.
Related
I have a tableviewController class where i am displaying my content in the tableview. Here, i want to add a scrollview below the tableview but i am not able to change the tableview coordinates. My TableviewController is in turn added to a navigation controller. As of now i am able to add the scrollview using self.view addsubview:myScrollView but it is getting added to the tableview. When i scroll the tableview the scrollview is also getting scrolled vertically. But i want the scrollview to be fixed below the tableview and i just want my scrollview to scroll just horizontally. Please help.
It seems what is happening is that you are adding a UIScrollView on top of the view stack and so causing it to rest on top of the UITableViewController instead of beside it. This is not good.
You should consider using UIViewController instead of UITableViewController. You could then subview a UITableView with a UINavigationController and a separate UIScrollView to fit the screen how you want it.
This is a pretty major undertaking, so it will be hard to demonstrate a good answer in code.
What you need to do is make your view controller a subclass of UIViewController, then add UITableViewDatasource and UITableViewDelegate protocol in your header file. If you are instantiating in NIB, toss your Tableview instance and replace it with UIView. You then hook to your FilesOwner as your view. then bring in table view object from the library and hook its delegate and datasource to file owner and you should be good! Hope this work well for you. Work well for me all the time!
I have this structure:
UIScrollView:
View
View:
UITableView
I have set all in a XIB file.
When I click in a row of the UITableView inside the limits of its view in the XIB file, it´s ok (it goes to didSelectRowAtIndexPath method). But if I scroll and then I click in a row of the UITableView beyond the limits of the view size in the XIB file, it does not go to didSelectRowAtIndexPath. What is happening and how should I correct it?
Thanks.
the scroll view delegate methods will get called when you scroll a table view...
i think the code written in side the scroll view delegate methods are creating the problem in your case...
check those methods once...
if it is like so to avoid the execution of code in the delegate methods write these lines
if([scrollView isKindOfClass:[UITableView class]])
return;
I have UINavigationController with UITableViewController as the root view controller. UINavigationController has a an optional UIToolBar, but I want to have a UITabBar instead. I don't need a UITabBarControllerbecause I don't want selecting tab bar items to change the view, just the contents of the same view. My app is a basic RSS reader which displays the items in the table view and I want to use the UITabBar to select from 2 or 3 different RSS feeds, refreshing the existing table view in the process, not switching to a different table view.
If I add a UITabBar manually to the UITableViewController (as it seems impossible to do this form IB) it is anchored to the last cell in the table view, so not only is it not usually visible, but it also moves around. I can't seem to find any way to do what I want.
The solution will probably be to use a UIViewController instead of a UITableViewController. This way you can have both a UITabBar and a UITableView, both subviews of your view controller's view.
The UITableViewController class reference describes exactly what behavior UITableViewController provides over a plain UIViewController (such as being the delegate and data source, deselecting rows, etc.) — you should implement all this this so everything works as it should.
You can make the UITableViewController a UIViewController <UITableViewDelegate, UITableViewDataSource>, and then hook it up in a nib with your TabBar. You can find the UITableViewDelegate protocols here. Hope that helps!
How is a UIActivityIndicatorView added to a UITableViewController?
I have tried adding it in Interface Builder and when I drag and drop it onto the view, it just disappears.
I need to show the activityIndicator while the table loads in its data.
If you put a tableview (not a tableview controller) inside another view you can place the activity indicator on top of it. To clarify:
- Plain xib file with a Files Owner and a First Responder
- Add a View (not a view controller)
- Add a TableView into the View
- Add an Activity Indicator into the View
For some reason, the various view controller objects don't like you adding things to them and the tableview object doesn't like you adding things to it. I'm sure that the docs make this really clear somewhere.
You can add UIActivityIndicatorView to your tables in the Interface Builder (IB), but a recommended way would be:
User IB to create and customize a UITableViewCell. Put a UIActivityIndicatorView inside this cell.
Programmatically load your table cells with the customized UITableViewCell nib file.
Programmatically hook up IBOutlets of such UIActivityIndicatorView.
In a view of my app I subclass tableViewController and has an activity indicator shown up when the table content is loading. I put it in the center of the screen but it scroll with the tableView (I guess the reason is I add it as a subview of the table view). Is there a way that I can keep the activity indicator in the center of the screen even the table is scrolling?
You could either subclass a UIViewController instead, and set a table property, adding a UITableView as a subclass to the UIView, making it behave exactly like a UITableViewController.
Or, more simply, you could just add the UIActivityIndicator as a subview to the main window.