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.
Related
I am working on a swift project in Xcode right now and one of my view controllers is a UITableViewController. I used swift to alter the size of the table view in the controller so that it does not fill up the entire screen. However, I want to set a background image for the entire view controller which I am unable to do since XCode is not letting me add an image view between the table view controller and the table view. Is there any way to do it using swift? Thank you.
I think I can help out.
If you're using Apple's UITableViewController - does that mean you altered the tableView's height in the storyboard? I think a better solution is to just use a regular UIViewController, add a tableView with whatever height you want it inside a UIViewController's view.
Often times I would recommend steering away from using Apple's custom things because you lose flexibility. Just make your own custom thing instead!
UIViewController > View > TableView & UIImageView
Make sure your tableview has a clear background!
How does one in XCode XIB builder add a UIImageView to an existing MasterViewController that has a TableView and is based on NavigationController?
Scenario
For example if you create a new project based on MasterDetail in XCode 4
Then look at the MasterViewController.xib file - so want to add a UIImageView to this that could be used to overtake the screen up until a point after which the image view is made hidden to disappear.
I'm trying to drag a UIImageView onto the page, and putting it just able TableView in the Objects column, however this doesn't work. Doesn't even show the image.
So even just knowing how to drag-drop an image onto the MastViewController.xib such that it takes over the screen at startup would be a step forward (not sure if I need a view to encapsulate both the UIImageView and the TableView?)
Background
Want to have an intermediate image that the iPhone app shows as it starts up
Idea would be start up (static) image is show, then straight away go to MasterViewController which would show this same static image with an activity indicator on it
Then when (is a background thread) the data preparation is down, the UIImageView could be made non-visible
PS. Some additional notes:
Initially there is just a table view you see in MasterViewController.xib.
If I drag an imageview in at the same level as the TableView it doesn't appear.
If I create a new view in the XIB and put the tableview and uiimageview under this, I get an error when running "'-[UITableViewController loadView] loaded the "MasterViewController" nib but didn't get a UITableView.'"
Is there a view or just a table view in your xib? If you want both a image view and a table view in the same view controller, you should have an ordinary UIViewController and let in implement UITableViewDelegate and UITableViewDataSource protocols and add a table view and a image view to its view.
so solved by:
creating a top level "view" in the XIB
put the UITableView & the new UIImageView under this new view
but, had to change the interface line to inherit from UIViewController NOT UITableViewController
Just add Default.png in resource.
I am new to UITableView, so please don't mind me asking the following silly question(s).
In the attached screenshot, the IB's geometry does not match the geometry on the simulator - notice the white bar at the bottom of the screen in the simulator. What did I miss? The outlets for the TopLevelView, TableView and the DatePickerView are defined in the rootViewController.h file.
In the IB, I had set the background color of the TopLevelView to lightBlue; the background color of the tableView is set to ClearColor in the rootViewController.m file. But, the lightBlue color of the TopLevelView is not shown around the edges of the TableView.
[ivTableView setBackgroundColor:[UIColor clearColor]];
See the screenshot here
Regards, Sam
The "white bar at the bottom" problem suggests that you've got a view controller that doesn't seem to know that it's inside a navigation interface. You should show the code or otherwise describe how you're assembling this interface, because there's something wrong in how you're doing it.
The root view controller of your entire interface, the one whose view appears as the sole immediate subview of the window, should be a UINavigationController. Its rootViewController should be the view controller that fetches this view from the nib. Beyond that it's hard to help without knowing more about what you're doing.
I suggest that you start with the Navigation template. Unfortunately its RootViewController is a UITableViewController, which isn't going to work here because that's only for the case where the table view occupies the entire interface. So turn the RootViewController into an ordinary UIViewController. Now in the RootViewController.xib design the interface you've drawn above. It should load properly, convincing you that you're on the right track.
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 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...