Set background image of a mutated TableViewController - swift

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!

Related

Scene Dock in Apple's Date Cell Example?

I am looking at Apple's Date Cell (Date Cell Link) example project and I have a question about the Scene Dock in MyTableViewController. How come there are items extra items in the scene (Like Picker and Done) that are next to First Responder, Exit, and My Table View Controller? How can this be done? Also, how is this helpful?
This image shows the Scene Dock that I am referring to. Don't mind the titles, I renamed the project.
This image shows the Scene Outline for MyTableViewController, where the Picker and Done Button are shown next to the My Table View Controller, First Responder, and Exit and not within My Table View Controller.
This image shows an expanded outline for My Table View Controller where the Picker object is found also. But not Done Button is nowhere to be found inside My Table View Controller.
This image shows the code to connect to Picker and Done Button There is nothing special to this.
When I delete UIDatePicker in the scene of the controller (not in the cell), the inline DatePicker still works.
I think this sample is meant to support iOS 6.1 or earlier, to reveal the UIDatePicker as an external slide-in view, so it needs to be in the controller for IBOutlet connection.
Hope this will help.
Normally, the MyTableViewController should not be of type UITableViewController but its superclass UIViewController. This is normally necessary because UITableViewController has by definition its main view property set to the table view. It is then difficult to place other views into this view.
With a UIViewController, however, you can add any number of views. This is necessary in this case to accommodate the button and picker. The table view controller functionality can still be achieved by manually adding the UITableViewDataSource and UITableViewDelegate protocols and overriding the appropriate methods.
However, Apple here shows that it is possible by placing the other views on the same level as the main view, the table view. This is admittedly quite confusing. I usually prefer adding non-standard views as subviews to the view of a plain UIViewController.
You can drag things like picker views from the library to the scene dock to add them there.
As to the utility of doing this, I have no idea what that would be.
In this case I think that the picker and done button are left over from the writers of the code experimenting with ideas and forgetting to delete them. To verify that just delete the picker view and done button and see if everything still works.

ToolBar between UINavigationBar and UITableView?

I have a UITableViewController embedded on a UINavigationController. This tableView is an instance of NSFetchedResultsController.
I need to add a Toolbar between the NavigationController's top bar and the TableViewController, but I can't figure out how to do it (I don't even know if it's possible).
I want to do something like Apple did with their WWDC App (except that they don't have the TableViewController embedded in the NavigationController).
I need to have some controls on the bar to drive the NSFetchedResultsController.
Some people suggested to people with similar problems to use a UITableView instead of a TVC, but I do need to have a TVC as an instance of NSFetchedResultsController.
Any ideas on how to accomplish this?
Would I have to do it programmatically? If so, how?
Btw, I'm targeting iOS6+ with storyboards and ARC.
The approach I prefer is to use a UIViewController at the outer level, containing your toolbar and a container view that holds the table. Then build your table in a separate UITableViewController and wire it into the container view using an embed segue. Overall, I think this makes the code more modular and easier to follow because the high-level structure is laid out in the storyboard.
The steps to use an embed segue are as follows:
Control-drag from the container view to the view controller you want to embed and select the "Embed" option.
Give the embed segue an identifier in the attributes inspector.
Configure the table view controller in the parent's prepareForSegue method, checking for your segue's identifier.
There is an example of this in my VCollectionViewGridLayout library. Take a look at the Sort & Filter example project.
Technical Note TN2154: UIScrollView And Autolayout provides another solution:
Note that you can make a subview of the scroll view appear to float (not scroll) over the other scrolling content by creating constraints between the view and a view outside the scroll view’s subtree, such as the scroll view’s superview.
That is, even if a scroll view (such as a table view) modifies the subview's frame, the auto layout engine will reset it on the next layout pass.
you need use UIViewController, then add tool bar and tableView instance of NSFetchedResultsController class inside it in storyboard
You can make a topBar of any UIView and then pass it as the tableHeaderView.
It may help you.
Use UIViewController instead of just UITableViewController where you can easily place other controls apart from just a UITableView.
Hope this helps.
You can use the UITableViewController (keep the niceties such as UIRefreshControl support and keyboard avoidance). You just have to embed your toolbar in a plain view and place that in your tableHeaderView. Then implement this scroll view delegate method to lock.
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.toolbarContainerView.frame;
rect.origin.y = MIN(0,scrollView.contentOffset.y + scrollView.contentInset.top);
self.toolbarContainerView.frame = rect;
}
Note that if you also use section header you will have to send those views behind your tableHeaderView otherwise they will float over the tableHeaderView.

how to add UIImageView overlay over a UITableViewController based controller?

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.

How to programmatically adda breadcrumb view to my UINavigationController App?

I have a UINavigationController App. I want to add a small bar just below the UINavigationBar, around 20px height. y application is almost finished, so I want to rebuild as less code as possible. For example, if I wanted to add a button in the bottom of every view of my application, I can do that by extending UIViewController with a category, and adding a UIButton as a subview of the current controller view, maybe in the viewDidLoad method.
This approach works fine, and so I can add my UILabel to all my views at the top of them. The problem is that it does not TAKE SPACE. It is always on top of my previous views (UITableView...). What is the best way (or just one way) to accomplish such a thing without having to create for example a view with 2 frames, and having all my main views extending it?
I thought of changing UINavigationBar height, but that is definitely not an option.The prompt property of UINabivationBar is just to big (around 30px).
I also tried to create a new view in the viewWillAppear method of every UIViewController, adding to that view my breadcrumb subview, and the original view, but it is not working.
Any ideas on this?
Thank you!
If I were you, I'd make a new UIView subclass to represent this thing, and embed it on the views of the individual UIViewControllers. They can get at the navigation stack by looking at the UINavigationController's .navigationControllers array, walk that and get view titles, etc.

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.