How to set UITableView to Grouped? - iphone

In an iPhone navigation based app, I want to add a second tableview but have its design available in IB. I've added a new empty XIB and dragged a UITableView onto it. I want to setup the layout through IB. I've created a controller for this tableview and set the File's Owner class in IB to this controller. I linked the tableview to File's Owner as well. I set the tableview to grouped in IB. However, that does not translate at runtime. I still have a plain tableview. In fact, none of the Inspector settings work at runtime. What have I missed?

Make sure when you instantiate the view controller you do so using initWithNibName:bundle: using the name of the file you've created.

UITableView *myTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0,80,320,480) style:UITableViewStyleGrouped];

Select your tableview and open it's inspector. In the first tab of the inspector, expand the "TableView" and you should see an option called Style. Change it from "Plain" to "Grouped".
If you can't find this, try this on your viewdidload
tableView.style = UITableViewStyleGrouped

Related

Can't create outlet using Interface Builder - Lock symbol shown

I'm trying to create outlets using the Interface Builder, however when drag the UILabel from the IB to my controller's .h file the big lock symbol flashes for a few seconds and it doesn't actually create the bind between the UILabel and the outlet (although the code is generated). I also noticed an empty circle is created by this new definition. When it worked, a filled in circle was created on the side).
I've checked the UILabel and all parent views and have checked that their "Lock" property is set to "Inherit (Nothing)" (and have even set them all to "Nothing").
In the IB the UILabel doesn't show the "x" that appear when a UILabel is locked either.
So I have no idea if I'm missing to unlock something, or what I'm doing wrong to be able to create this outlet.
I don't know if this is relevant, but I'm using a custom view controller, and I'm using this same view controller subclass for 2 different view controllers in the same storyboard. I had no problems creating outlets this way for the first view controller.
Tryed reopening XCode (using 4.4.1) with no luck.
Any help is appreciated!
So are you dragging both UILabels from each View Controller into the same file? I don't think that this is possible, on the second view controller, try to Ctrl drag to the file owner within the IB view, that is, assuming that both views are connected to the same instance.
Also, in your identity tab in storyboard, under Localization Locked, make sure your storyboard locked setting is set to default as mentioned in https://stackoverflow.com/a/11169636/720175
I tried adding a totally new scene and would also get the lock symbol. So it wasn't only the scenes, but the whole storyboard. So a quick search on SO lead me to the answer:
https://stackoverflow.com/a/11169636/720175

NavigationController as a subView

I'm new to iphone development. I have a tabBar App, designes in interfaceBuilder.
When I pressão the About button, it flips to a view where I put the App info. In this view, I need to have a navigaionController with a tableView.
How can I do this?
I'm having a lot of trouble to do this.
Anyone can help Me?
iChat: Rui.Lopes#Me.com
So, I guess you simply want to show a UITableView inside a UINavigationController inside a UITabBarController. This is fairly simple:
First, you should create the ViewController which will contain your TableView. You might have already done this, so just the quick walkthrough: Click "New File" and create a "UIViewController subclass". It's easiest to check "UITableViewController subclass", but a more flexible approach would be to subclass UIViewController and fill it with a TableView in InterfaceBuilder or programmatically. If you need help here, just ask.
Once you created your "AboutViewController", open your TabBarController (most likely in the "MainWindow") in InterfaceBuilder. Now, select the TabBarController, and add a new Tab in the Inspector. Change the Tab's Class from ViewController to Navigation Controller. Inside your newly created NavigationController, there will be a "View Controller (Item)". Select it and, in the Inspector, change it's class to "AboutViewController" (or however you called it). If you created a XIB for your AboutViewController, don't forget to change the value of "NIB Name" in inspector.

UITableView with fixed image background

Sorry but I found no clear answer on that.
I have an iphone app with a tab bar and a UINavigationController in each tab.
The interface is built with Interface Builder, and in the first tab there is a UITableView.
I have prepared the xib with main view (A) containing a table (T) and an image (IMG) background behind (image as subview of main view).
Later I assigned UITableViewController as owner. This is where problems start.
In IB if I connect view to A I got a runtime error telling me that controller cannot find a table.
If I connect controller view to T everything works fine, except that IMG is not shown.
The only solution I found is to create a new xib holding A and IMG with a UIViewController as owner. Then create a xib holding T only and UITableViewController as owner, correctly connected to T.
Then in viewDidLoad of the UIViewController:
iptc = [[IPPlantsTableViewController alloc] initWithNibName:#"IPPlantsView" bundle:[NSBundle mainBundle]];
iptc.navigator=self.navigationController; // <-- need this
[self.view addSubview:iptc.view];
And this works, except that the table view seems to not know anything about navigationController, therefore detail view mechanism is not working, unless I set a property for it in UITableViewController.
I also run in to some other problems, for example all the logic for adding/deleting/creating rows to table has to be handled in UIViewController and sent to UITableViewController.
Is there another way for having a fixed image in a table view ?
Mmmm
I will be honest i HATE Interface Builder ;-) so I can't help you about this.
But to set a fixed image in the background of a UITableView you should :
- set background color of the UITableView to [ UIColor clearColor ] (and maybe the background of the cell too)
- set and uiimageview below the uitableview view that contains the image :)
In that way this should work.
But without xcode project I can't help you more ^^
Good luck
UITableViewController is a convenience class; you can equally just use UIViewController and implement the correct callbacks.
In OS 3.2+, you can just set UITableView.backgroundView. If IB doesn't let you do this, you can do it in code instead.
Alternatively, you might be able to wire up the view and tableView outlets differently, unless tableView just does (UITableView*)self.view.

UItableView + UItabbar

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.

How to use UISearchDisplayController from a controller within an UITabBar controller?

I have an UITabBar controller managing several controllers (using SDK 3.0). One of these is a tableView controller and I need to provide a search capability using the UISearchDisplayController. All of my code is based on Apple TableSearch example. However, when clicking on the tab, the tableView controller appears showing its related content, but no searchBar appears. I have checked the xib in IB to make sure that all of the outlets are properly set, but no matter what I try self.searchDisplayController is always nil and the search bar does not appear.
In practice I have replicated MainView.xib from the TableSearch example and set the file's owner class to the correct controller class for the tab. The outlets are sets as in the example MainView.xib. Am i missing any important step or doing something wrong?
Thank you in advance.
I had the same issue and happened to stumble upon this solution ...
If you have your table view controller (eg. UISearchDisplayController) nested in a Tab Bar or Navigation controller using Interface Builder, you need to set the "Nib Name" in the "Attributes Inspector" window.
The Nib name will be the one that holds the table view and has the controller (eg. UISearchDisplayController) as the File's Owner.
I too have this issue :( Is the search bar getting hidden behind the tableview?
#unforgiven,
did you try this...?
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
[self.tableView setTableHeaderView: searchBar];
This manually creates a searchbar and it works. But I'm making some stupid mistake in IB that the SearchBar doesn't show up even though my connections are perfect. :-(
Do update this post if you get the answer...
Ok, I have found how to solve it. In my case, the problem was due to the fact that I was using a controller embedded within the UITabBarController as one of its managed tabs (i.e. as a child).
Removing the controller from the UITabBarController, then adding an UINavigationController to the UITabBarController instead, and finally putting my controller as a child of the UINavigationController solved completely the issue.
I do not understand why this is so (there is no related information in the documentation, as often happens); however, it now works like a charm.
With kind regards.
I had a similar issue
To solve I had to do one additional step to unforgivens answer
In my main nib
1) create a UITabController
2) Then I dragged out a UINavigational Controller into the tab controller
3) Then dragged out a UITableViewController into the NavigationalController as a child
4) Then changed (3) class to be my MyTableWithSearchBarViewController in the inspector - check if the nib name is correct and change this if necessary in the inspector as well
5) I then had to delete the tableView which is automatically created by IB in step (3). Only then would the search bar show correctly...
If in step 3 I dragged out a different controller onto the stage or left the tableView there it would only ever display the table and not the search bar
weird
Tomtrapeze has the right answer if your nib file contains the UITableViewController. But, if you're loading the UITableViewController in code -- such as pushing it on the stack of a UINavigationController -- the solution is a little different.
When initializing the UITableViewController or subclass, you need to use the -initWithNibName:bundle: form of initializer and specify the name of your nib file. Alternately, you could use the standard -initWithStyle: initializer and manually set the nibName property before the view is loaded.
If the nibName property is not set when the view gets loaded, UITableViewController will not use the normal UIViewController nib lookup logic. It will just load a standard UITableView instead.
I recently learned that I could load NIB files with [[MyViewController alloc] initWithNibName:nil bundle:nil]; when the NIB file has the same name as the class (i.e. MyViewController.xib). It turns out that initializing this way causes the 'UISearchBarandUISearchBarDisplayController` to not display. When I initialized the view controller by actually typing out the name of the class, my search bar showed up correctly. I initially thought it had something to do with how I was presenting the view controller but was glad that it wasn't.
PGWSearchViewController *searchVC = [[PGWSearchViewController alloc] initWithNibName:#"PGWSearchViewController" bundle:nil];
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
searchVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:searchVC animated:YES completion:^{ }];
This is using iOS SDK 5.1 and XCode 4.3.1.
Another possible fix that works for me is to init the UITableViewController with initWithNibName:bundle:
SearchEntryTableViewController* searchEntryTableViewController = [[SearchEntryTableViewController alloc]initWithNibName:#"SearchEntryTableViewController" bundle:nil];
To nest the UITableViewController in a UINavigationController before put it in a UITabBarController doesn't fix the issue for me...