It'a s simple app, window based.
The window has a UINavigation Controller, and the Controller has a UITableView built from
New File-UIViewController subclass- UITableViewController option check.
I set the style for the UITableView to Grouped in the Interface Builder, but the table stayed Plain in the Simulator.
I wonder if I missed any options?
XCode 3.2.6
iOS SDK 4.3
Any help is appreci
Project download: Zip File#Google Docs 692k
tViewController is a subclass of UITableViewController so it's creating a tableView for you and ignoring yours. Change the superclass of tViewController to UIViewController and it will use the tableView you have defined in IB.
Make sure you've properly specified the nib file (remember: iOS is case sensitive) for the controller and connected the table in the nib to File's Owner. Otherwise, the controller will create its own table, which is probably what's happening.
Related
I am loading a viewController via a storyboard segue and I want to add a UIImageView to the controller programmatically (instead of creating it in the storyboard). Usually when working without a Storyboard or NIB I would do this in loadView: is there an appropriate place for this when using storyboards or does the storyboard drop you in a bit late in the day for that?
EDIT: Updated error regarding NIB and loadView:
If you're using a NIB you shouldn't really be adding anything using loadView:. You should be using viewDidLoad:. This also works when using Storyboards.
I have some UIViewControllers from my old iOS4 project, they are using .xib, created in interface builder.
My new project, built for iOS5, uses storyboards.
I'm trying to add a UIViewController to the storyboard, but have it use a custom XIB that I already have. I've set the controller's identity in the indentity inspector (in interface builder), but am not sure how to ask that controller to load a custom .xib.
Any help is appreciated!
PS. Up to date I was able to get around this by creating a "wrapper" class for the storyboard purposes, and have that class have another UIViewController. But this kinda defeats the whole point of a storyboard.
You could copy the contents of the xib into the storyboard and then instantiate it using:
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier
after setting the identifier on it. If you need the instance of the storyboard you can get it this way:
[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
Mike K's answer is false.
While mixing XIBs and Storyboards doesn't really solve Alex's problem, it is quite possible to do within the same project.
See: https://stackoverflow.com/a/8516479/1309238 re: loading a second storyboard.
I'm not sure if including a "Main Storyboard" in your Target Summary is advisable if you plan to do this, but if you've loaded a XIB instead of a storyboard to begin with, you can modify the code linked above to load the storyboard after the XIB.
I'm not sure if you can jump into the middle of a storyboard from a XIB, which may have been what Mike meant.
You cannot mix xibs and storyboards in your project -- it's one of the other, I'm afraid.
I"m having some issues trying to manually convert a UITableViewController to a plain UIViewController. I need to change some of the layout of the view, so I'm just planning on creating a UITableView manually and positioning it on the screen myself.
I deleted the automated xib file that was generated by default from the project creation process. I changed the view controller to subclass UIViewController instead of UITableViewController as well and have it set adhere to the UITableViewDataSource and UITableViewDelegate protocols.
I also set a UITableview *tableView property & synthesizer, but I did not manually alloc or addSubview with it.
However, when I launch the app and the view loads, the tableView still shows on the screen. I just don't understand how this is happening.
There has to be some kind of vestigal code that was created automatically that I'm not finding and need to clear out, but I've looked through all the related files (app delegate, view controllers, xibs, etc...) and I can't seem to find anything.
You need to make some changes in nib file also. Try changing nib files connection.
UItableView style not changing. I have a tableView controller as one of the tabs of my tab bar controller. I am not able to change the style of UItableView to grouped.
Please help,
You must specify the Tableview's style upon creation. Either in IB or by using the method
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,416) style:UITableViewStyleGrouped];
I would create a new tableViewController and make sure to enable the "also create xib"-like option when giving the tableviewcontroller a name. Copy paste all youre old tablviewcontroller code to the new one and add the xib to the tab window..
You can probably do that in your UITableViewControllers -viewDidLoad method.
self.tableView.style = UITableViewStyleGrouped;
Edit:
It seems the style property is actually read only, so the above won't work.
It looks like the table view controller has to be created with -initWithStyle:, but I don't know how to do that from Interface Builder. I'm not at my Mac right now, but will have a look later.
Edit 2:
Here's what I did in Interface Builder:
Add an instance of UITableView and set it up as required, including the style
Hook up your UITableViewController as the delegate and data source of the UITableView
Connect the UITableView with the view outlet of the UITableViewController. I'm not sure if there is a tableView outlet - if there is, then probably connect it with that one instead.
So, basically, instead of letting the UITableViewController create its own table view, you provide one in the xib and set up the required connections (delegate, data source, outlet) manually.
I'm having trouble creating a UIView (in Interface Builder) that contains a UITableView with some other object, such as a UIButton or UILabel. The UITableView always takes up the maximum amount of space in the UIView, regardless of the size of the UITableView object itself. The File Owner is a standard UITableViewController.
Here's how to do this easily:
1) Create a table view controller with xib.
2) Change the inherited type in the .h file from UITableViewController, to UIViewController.
3) Add the protocols UITableViewDataSource, UITableViewDelegate to the .h file.
4) Open the xib, add in a view.
5) drag the table view in the xib under the view, resize as desired.
6) Wire the "view" property of the File's Owner to the View instead of the UITableView. The datasource and delegate properties of the table view should still be wired to File's Owner.
7) (optional) if you want to be able to reload or otherwise access the table outside of table view controller delegate methods that pass in a table view, make a UITableView * IBOutlet named "myTable" or the like, and wire the table in IB to that.
An alternate approach is to make a new UIViewController with xib, add a table to the xib, wire datasource/delegate to the file's owner, and make a new UITableViewController class which you use to copy the methods from into your view controller, then delete.
Unfortunately, creating a UITableView in Interface Builder (IB) is was very problematic for me. I ran into the same problems as you as a beginning developer and, after much frustration, just ended up abandoning IB for UITableViews.
The best solution for me was to just implement the UITableViewController (and the UINavigationController that you use as a header) programmatically. Once you figure out the whole Model-View-Controller paradigm, it is actually fairly straightforward.
Some good resources for dealing with them programmatically can be found in Apple's documentation with these names:
"Table View Programming Guide for iPhone OS"
"View Controller Programming Guide for iPhone OS"
Cocoa with love has an article about Recreating UITableViewController to increase code reuse. This is useful if you can't use a UITableViewController, but want to make sure that your UIViewController will behave the same way.