Implementing another table view in a UITableViewController ios - iphone

I need to add a new table view to my UITableViewController which will includes a different data and design.
the above prototype cells is the new table view I've added in storyboard, and the main table view is the second one which includes (title, label, and image).
Is it allowed to create another table view in UITableViewController, or should I create a UIViewController and implement the two tables in it???
In fact, I've finished the implementation of the first table view controller, so I need to implement the new one.
the attached image is showing what I want:

You will be better off with a UIViewController that has two tableViews as subviews if you want both of your tables to be shown at the same time. UITableViewController should be used only when there is just one tableView shown at a certain time.
You can either have one UIViewController being the dataSource and delegate for both of the tableViews, or have a UITableViewController for each of your tables and add them as subviews to a UIViewController that will be a container view for both of them. The latter will probably save you some time debugging possible issues as having two tableViews with a single delegate/dataSource requires a lot of duplicate code in the same place.

I think you should use UIExpandableTableView
there is detailed usage on github page
Scree example of UIExpandableTableView

Are you looking to have them be two independent tables, or is it a master/child setup?
If they are independent, I suggestion using one table and two sections, then depending on the section number return to correct cell.
For master/child, think about making a view that looks like a cell and have the master cells be the sections views and the children be the actually rows. You can make a section class that stores if the children are visible or not and in the numberOfRowsInSection method return the count if visible or 0 if not.
Just a couple ideas

Related

Difference between table view controller and a table view placed within a viewcontroller

I am making an app and would like to direct my user once they log in into their dashboard, I have seen some apps display things in what seem like a table view controller or a view controller with a table view. I would like to display the logo up top and then a table displaying their username then about 4 more rows displaying other info then at the bottom a tab bar. What would be the best way to go about this?
any advice welcomed. If relevant I am using swift, Xcode7 and parse to handle my users
Use a UITableView. This a bit more customizable in terms of Storyboard layout. You can place UIImageViews, toolbars, and other elements all over your UIViewController. You can then put a UITableView in the exact place that would work for you, with the dimensions you need.
Of course, you could always use a UITableViewController. You could embed this controller in a variety of combinations, which would let you add tab bars or navigation bars.
The only real difference in implementation is that you have to remember to explicitly write the delegate and data source methods when using a UITableView.
For your case, I would pick whatever seems easiest to implement in your case. Probably a UITableView in my opinion.
Some differences between UITableViewController (TV) and UIViewController with TableView (VT) I know:
You can add other controls into VT and pin it to anywhere you want. TV can't do that.
You can add many same group of controls without add constraints with TV. VT you have to add constraints.
You don't want to worry about scrolling in TV with many group of controls.
With TV you can create static table cell but you can't with VT. Static table works on TableViewController only.
In your situation, I use UITableViewController with static table to achieve that.
Hope this can help.

IOS create new UITableViewCell with properties of a prototype cell

I am working on an app that has several prototype cells in one view. This worked well for easily altering the appearance of the app while in development using the storyboard. However, now I'm adding search (filtering) capability. I would like the appearance of the tableview to remain unchanged, just filter out some of the results.
My understanding is that I have to create new cells to do this. Is this correct? If it is, is there a way to create a cell with all the properties of my prototype cells. As it is now, the newly created (search result) cells have default settings.
Thanks.
You can certainly use copy and paste. Create a xib file (an empty one), and copy the cell you want from your table view in the storyboard, and then paste it into the xib file. In the viewDidLoad method for your table data source, register that nib file:
[self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:#"SearchCell" bundle:nil] forCellReuseIdentifier:#"SearchCell"];
Then in the cellForRowAtIndexPath method, you just dequeue a cell with that identifier for your search results table view.
The thing to understand clearly is that the table view that appears when you are doing a search with the UISearchDisplayController conglomerate is not your table view. It is a different table view, and you do not have a UITableViewController managing it - the UISearchDisplayController does that. Thus you must take other measures if you want that different table view to look like your table view.
EDIT: On the whole (and after the little exchange with rdelmar in the comments on his answer), I tend to think the easiest solution is to abandon the use of cell prototypes altogether. If you design the cell in a nib (xib), you can then use that cell both for the real table and for the search results table. In both cases you register the nib with the respective table view - and then dequeue just does the right thing all by itself, in both cases, with no change in the code.
You can see me doing something similar here:
https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch21p632searchableTable/p536p550searchableTable/RootViewController.m
... except that in that case I'm registering the same cell class for both tables, not the same nib. But it all comes down to the same thing. However, note that I do not start with a storyboard, so I never fell into the trap of using a prototype cell in the first place.

Same UITableView in different viewcontrollers?

I have an application that has multiple viewcontrollers and one common menu table.
Menu table is same in all viewcontrollers. Currently, If i want to add some more menu in my menu table then I have to change in all the view controllers.
Can we have a common table view which can be called in different viewcontrollers?
Thanks
Make a subclass of UITableView and create your menu in that like :
#interface menuTable : UITableView
Then you can use the instance of that class in all viewControllers.
Yes, you can.
When you add UIView to some other UIView, former will be removed from it's Superview and added to latter as subview. Remember to be careful with view's frame. e.g. convert it using convertRect:toView: selector
As I understand ur question, just create a tableView in CommonView (a ref. name) and as per your need you can call that table view. By this way you have to not change many times in your code.

reuse view from storyboard

I have a tableview with custom section headers. The view for the section header is defined in the storyboard and wired to an instance variable. Is there a way to request a new instance of the view from the storyboard?
In the past I have done this by having the section header defined in its own xib file and getting a new instance by using
[[NSBundle mainBundle] loadNibNamed:#"TimerViewSectionHeader" owner:self options:nil];
UIView *newHeaderView = self.sectionHeaderView;
I dont' think there is a way to do that. Best bet is to put the tableview custom header view in a separate nib and load it like you did in your code sample whenever you need to use it.
I tried to do the same thing and ran into the same problem.
I like to work with storyboards a lot and was impressed how fast I could create a working UI. However, as soon as you need to re-use views it makes a lot of sense to put those into a separate nib along with its UIViewController subclass.
You can then place a generic UIView in all the places where your re-used view should go and add the view using your ViewController:
[myReusableViewController loadView];
[myReusableViewController viewDidLoad]; // You have to handle view callbacks yourself.
[self.myReusableViewPlaceholder addSubview:myResusableViewController.view];
[myReusableViewController viewWillAppear:YES];
So to sum it up:
Use storyboard, it's great
Create the scaffold of your application in the storyboard, along with any static view (like About screens etc.)
Create re-used views in a custom nib + UIViewController subclass and add UIView placeholders in your storyboard.
In another answer I thought about some Pros and Cons of Storyboard
The solution I've come up with for this is as follows:
I have a tableview with multiple prototype cells that displays complex data. There is a segue to a detail view, and a transaction process view.
This first tableview has a search button that displays a new tableview with the results. It needs the same functionality as the main tableview that pushes it; including segues to the detail and transaction progress views so:
On storyboard, select and copy your main tableview. Deselect and paste. Create a push segue from your main tableview to your 2nd tableview; or from where ever you want to navigate to it from. Modify the 2nd tableview as you like. IE: If it requires some UI changes no problem.
Create a new viewcontroller class that is a subclass of the viewcontroller running the main tableview.
Override the data delegate in your subclass to serve up the subset of data you want.
Back in the storyboard, select your 2nd tableview controller and in the identity inspector select your subclass as the custom class.
For this solution to work smoothly, your app really needs to be managing data for the views. You could use prepareforsegue to pass data from 1st tableview to the second, but I've found the app data model far more flexible from numerous points of view.
Unless you have buttons that push to the sub views via segue, your subclass will need to override functions that push via segues with identities. NB Segues must have unique identifiers if you id them at all.
It took a lot of trial and error to figure this out, but once you understand the concept, it's a relatively smooth solution that is quite adaptable and not so bad to implement.
I am not sure about just views, but the way that I was able to get view controllers out of my storyboard is as follows.
UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierName"];
From here, perhaps you might be able to use this similarly to how it was once done with nibs.
I've been able to reuse a view in the storyboard just by connecting a transition from one tableview into the one I want to reuse.
so my tableview that I want to reuse is pointed to twice.
It sort of works but the problem I'm running into it setting a variable (using instantiateViewControllerWithIdentifier) in my app delegate to my table view that is getting reused.
It seems that if I reuse it, the storyboard is creating 2 instances of my tableview and the one I get with instantiateViewControllerWithIdentifier isn't the one I want.
I'm not really sure if this is the proper way to do it. But I assume many others are doing this somehow. With the custom table cells in storyboard I suspect lots of people want to reuse their views.
For example: We want to reuse the view(include subviews) in storyboard shown below.
The best solution I know so far is clip and paste the view related code to the New Singe View file without losing the information.
Detailed steps are as follows
Step 1: Rename the view we want reuse. Just prepare for step 2.
Step 2: Open storyboard as source code in order to clip the XML code we need
Step 3、4: Search and clip the code we need
Step 4.5(Not needed): Open as Interface Builder to see the view removed
Step 5、6: New XXX.xib and paste the code we clipped just now
Step 7: Important. Insert code<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> to XXX.xib source code.
Warning: Do this before open it as Interface Builder! Otherwise, you will see wrong size and layout waring.
[![step 7][9]][9]
Step 8: New XXX.swift to connect the XXX.xib
[![step 8][10]][10]
Step 9: Add the view anywhere we want
[![step 9][11]][11]
I get warning: "You need at least 10 reputation to post more than 8 links."
Can you support me to upload the remaining 3 screenshots?

Best way to handle multiple UITableViews in one UIViewController?

I have a UIViewController that should be capable of displaying tableViews with multiple data sources. The UITableView spans about half the size of the screen, and there is and up and down button that allows you to go through different data. Everytime the up and down button is hit, I'd like to ultimately use UIViewAnimationTransitionCurlDown or something similar to display the next UITableView.
The question is: do I need multiple UIViewControllers to do this, with a tableView embedded in each one? Should I just create one instance of UITableView and change its data source when an up or down button is hit? If it's only one instance of UITableView, how do I manage to get a curl transition over the portion of the screen it takes up to make it look like a new tableView is coming in?
Why not have each table view belong to its own UITableViewController, and nest these within the current screen's view controller? This way the screen's view controller is responsible for swapping out its subviews, each of which have a table view controller containing the necessary logic to show their data.
In the end, it comes down to what your functionality and data sets look like. It may end up being easier to implement the table view datasource & delegate code once, injecting an actual data source into this class - or it may be easier to write custom datasource code for each table view.