I'm building my app like that: one ViewController = one nib file etc.
But when I added collection view in my view controller for some reason I can't add cells to it, what is the problem?
Also when I drag the cell to this collection view nothing happens...
Same problem with TableView...
Nibs don't support adding cells to collection views or table views directly in the nib. Only storyboards do. To use a nib with a collection/table view in it, you would have to programmatically register your cell class (or cell nib) with the collection/table view.
Related
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.
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!
I created a window based application, and I created a separate UITableViewController file called "HomeViewController" which right now only has a basic table.
In the MainWindow.xib file, I put a UIView in the bottom half of the screen, and I wish to put the HomeViewController tableview within this newly added UIView called "conferences".
Any suggestions as to how to push this file?
First off, usually your primary first view originates from a view controller that is loaded by the UIApplication object. The MainWindow nib's owner is UIApplication so you probably don't want to be mucking with the MainWindow nib. Rather, you want to muck with the view of the view controller loaded by MainWindow nib. If you look at the view displayed in IB for MainWindow.nib, it should say which view controller's view it is loading.
So, in IB for the view of view controller being loaded by MainWindow nib, this is where you want to place your UITableView. For purposes of this explanation, I will call this view controller, MucksViewController and associated nib, MucksView.nib.
I think what I would do, then, is drag and drop a UITableView into the view for MucksView.nib. Position it in the bottom half of the screen, as you described. Attach this UITableView to an IBOutlet property in MucksViewController header file. Next, drag and drop a UIViewController object into the main window for MucksView.nib. Make this UIViewController object's owner your HomeViewController class and also attach it to an IBOutlet property of type HomeViewController in MucksViewController's header file.
Now, in MucksViewController's class file, probably in viewDidLoad method, programmatically make the HomeViewController object the data source and delegate of the UITableView object.
But, I'm wondering, do you really need HomeViewController? It would be cleaner just to make MucksViewController the data source and delegate.
I hope this helps and is not too confusing.
Instead of a UITableViewController, use a UIViewController which implements the tableview delegate and datasource. in your MainWindow.xib, add a standard uitableview as a subview to the view where it should be. then also drag a HomeViewController to the xib (which should now be a uiviewcontroller sub class). click on the tableview, open the inspecor, go to connections, and drag the delegate and datasource to the HomeViewController in the xib.
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.
Is it possible to position a view defined in a XIB as a subview in yet another view in that same XIB file? Alternatively, is there a way the "subview" can be defined in another XIB file and positioned in the first view in a different XIB? I've figured out how to do this for UIViewControllers but not for UIViews. Has anyone figured out how to do either of these?
You can view your nib file objects in a tree view and drag and drop one view to be a subview of another.