iPhone UITableViewController custom layout - iphone

I'm a beginner in iPhone programing. My first app is a UITableViewController but now I would like to experiment a little bit. The idea is to create a custom layout that would look like this:
The layout:
---------------------
Image | Button
---------------------
UICalendar
---------------------
UITableView
---------------------
Button | Button
---------------------
QUESTION 1:
As you can see I would like to add some additional UI elemnts. All the tutorials I've seen describe UITableViewController as a single UITableView (no other UI elements included in a controller).
So my question would be is it possible to extend UITableViewController to have that kind of layout? What is a proper way to do it?
QUESTION 2:
For UITableViewController I don't use XIB file but some people do. Why would I use XIB file when creating a UITableViewController? What are the benefits? What is the best practice?
UPDATE:
Actually what I'm thinking of is to have a separated controller for UICalendar (UICalendarController) and UITableView (UITableViewController). I just don't know how to implement that.
Thx.

The standard approach for the kind of thing you're trying to do is not to subclass UITableViewController or to use a XIB file to define the interface for the view connected with a UITableViewController, but instead to use a UIViewController with a XIB file that happens to include a UITableView in it.
You'll have to implement the UITableViewDataSource and UITableViewDelegate protocols in your UIViewController subclass, but this is not difficult.
UITableViewController is a somewhat brittle and limited class, unfortunately. It's not hard to create your own classes that use UITableViews, but it's unintuitive to many people that the right approach to doing so doesn't start with UITableViewController.

Check out the Tapku library. It comes complete with a Calendar / Table.

In iPhone, you can create every control by programming or you can use XIB. XIB makes the work simple by using native features of the control. If you want to extend the control and its features, create custom classes and create them manually.
Coming to UITableView, is your representation for one cell? Else you can create custom cells and add them to the table view. For creating custom table view cells you have to extend your class from UITableViewCell and implement them.

Related

The best implementation of a tableview in Model View Controller

What is the best implementation of a tableview in Model View Controller?
I'm developing my app without storyboard, all programmatically .
Is it possible to implement a TableView in a UIView? I tried it, but If I implement the TableView in a view, when the controller recives a button action, I can't modify or access to the tableView of the View...
After that, I tried to implement the tableView in a ViewController and it works perfectly, but I don't know if this is a good implementation because I found the same problem when I wanted to implement a TextView/TextField with a Piker, for example.
My goal was to had a clean code of viewController with a views and controllers (of buttons etc) and now I find myself with a uiviewController with the view and multiples components when I wanted the components were in the corresponding views.
Thank you very much!
It is all possible, and the problems you are running into are not because of it being something that you should not do, but that it is something that inherently works slightly differently than before. To answer your question directly, I would implement the tableView as the modal view controller directly, either as a UITableViewController or a UIViewController that inherits the table views delegate and datasource (this method being chosen if you don't want the table view to use up the entirety of the modal view controller's space).
TableViews are simple to use, but understanding every detail of how they work will make you far stronger and able to use them in any of these scenarios. I am not going to write you a guide on their use, butcontinue studying them before you declare that anything "can not be done".
Knowing what classes to implement the delegate methods becomes very important during these different scenarios. It is often easiest to use textfields delegate's implementation in UITableViewCell's subclass rather than in the UIViewController they are in. This allows for a more modular creation.
I find that working with the storyboard allows for a much quicker learning curve, and also a time saver. The one excuse I will give you for working without a storyboard is if you have an extremely slow computer.

IOS: How to create a Master View

I started a project with storyboards and it has a lot of views, each one of them has the same header (with an image, company name and two buttons). I want to do this once in the main View, and make it reusable for the other views. It’s like a master view with a header and footer. How could i do this?
This is my first project starting from cero and I want to make it as organized as possible. What are the best practices using storyboards and MVC?
Thanks in advance.
There is no special way of doing this in storyboard.
But you can do it easily by making custom UIView.
Make a sub class of UIView and pust all common design in it.
Place a UIView on top of every UIViewController.UIView.
Now set this top UIView's class with your custom class in identity inspector.
All the best.
A primitive way to do it in storyboard is to define there your master view, select all of its elements, copy them and paste them into the other views.
You can subclass UIViewController to add a header to its view, and UITableViewController to set it as the tableview header.

Reuse a custom UITableView in different UIViewControllers

I'm developing an iPhone app for iOS 5.1. I built a UIViewController which has a UITableView with a UISearchDisplayController and other views, all somehow related to the table. The UIVIewController is the delegate and the datasource of the table, and makes some customizations (graphical and business-related) to the table and search display controller. So far, everything was OK.
The problem is that now I want to put this same table (maybe with a different sublist of elements, of the same type) in different controllers (different screens of the app). I tried to add the tableView of my controller as a subview in other controllers, but it doesn't work. I tried to rebuild my table as a subclass of UIView (instead of UIViewController) and add it as a subview, but it neither worked (it loaded the view from a NIB file, but all its properties, including the IBOutlets, where nil or 0x000000).
After searching a lot, I didn't find any example of how to reuse a tableview in different controllers. Any hint? Any example? Should I build it as a UIViewController or as a UIView? Which class should be the delegate of the table and searchdisplay, keeping in mind that most of the logic I want to reuse is the code in the delegates?
Thank you all in advance
Wouldn't the easiest solution be to create your own Datasource class (maybe as a singleton) and then reuse this with the other controller? This way, your way of getting and managing the data is abstracted from the way of displaying it. Just the way it should be.
This is what MVC is all about.

Best Practices for refactoring controls and functionality out of a XIB

I have a regular custom UIViewController that loads a regular iPhone-screen-sized XIB. But I have a subview in the XIB that consists of a few components (UILabel, UITextField, UIButton) that I'd like to factor into a separate XIB, and move the logic controlling these components out of the UIViewController, possibly to a custom UIView object that would load the custom XIB.
I've searched Apple documentation without much luck, and searched for an answer here, but I can't seem to find a clean way of creating a custom UIView, instantiating it in a XIB, and dropping it into another XIB. Is there a clean way of moving this view into it's own XIB and the logic controlling it out of the custom UIViewController, so I can use it on multiple screens of my app?
(I'm not married to the idea of putting this functionality into a custom UIView, it just seemed like the obvious way of doing it to me. I'm open to any clean way of factoring this into it's own component.)
If you want to know about multiple views in xib u can go through this
Multiple Views within one XIB - iPhone SDK
This may help you.
If you want to create a view in xib without view controller go through this
Using a xib file without initializing a view controller
I think this should be useful

UITableView and a UITextField that is always visible

I want to create an application which combines a chat feature. My question is this: how can I have a UITextField that is always visible in the same view as a UITableView?
The obvious solution would be to create my own UIView having a UITableView and a UITextField below it, however the UITableViewController doesn't seem to like me doing that as it expects the connected "view" outlet to be a UITableView, essentially destroying my plans.
Anyone with an idea?
Don't use UITableViewController. After all, it's just a standard controller with a full-screen UITableView. You can roll your own easily.
Use a standard UIViewController and have it implement UITableViewDelegate and UITableViewDataSource protocols (you don't need to implement every method -- just the required ones). Then give it a UITableView as an iVar and set the delegate and dataSource to self. Size it so it only takes half the screen and your other views take the other part. You can lay out the whole thing in IB or create and position view+table manually.
I would suggest sticking a regular view in between your controller and your smaller "half-views". That has usually cleared things up for me, or at least exposed what the problem might be.
If you don't need functionality that UITableViewController provided, than you can just use
UIViewController with <UITableViewDataSource, UITableViewDelegate> protocols.
So, your main viewController will accept any type of views.