Displaying two UITableView - ios

I need to show two UITableView but I'm not sure the right way to do it. I tried to use two UIViewController each with UITableview and load those views to the parent controller's views but I had doubt on this implementation. I can't use UISplitViewController because I need more real estate on the left also I have navigation controller as the root controller. Then I saw Amex for iPad app (check the first screenshot) that seems to be the best way to show the tables. Is it a UIPageViewController? Any suggestions on the implementation? Many thanks.

It looks like an UIPageViewController with 2 UIViewController each with his own UITableView, but I would have to download and install to be sure of what I am saying. Nothing spectacular about it (at least in the implementation part if I am correct in my assumptions), the look, on the other hand, is very nice.

You can put 2+ UITableViews in one viewController. Then in all your delegate and datasource implementations check which tableView is being asked for. For example:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:self.tableView1]) {
// return cell for table 1
}
else if ([tableView isEqual:self.tableView2]) {
// return cell for table 2
}
}

Related

No data at all is showing in UITableView

I have created numerous Xcode projects to see if this was a single project problem but no. The problem that I am getting is that when I populate a UITableVIiew with either local data or data that is stored in a Parse database it does not show.
I have tried re-installing Xcode, cleaning my project and walking through the code/project to see if I'd made a mistake but everything looks in place.
An example is that I created a UITableViewController with a UIImage in the cell and when I build and run the project it does not show up.
Here is an example:
Thanks in advance.
You should implement two required methods of UITableViewDataSource.
Something like that:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
return cell;
}
This would go quicker if you just posted the available code... Annnnyway...
The reason I ask is because if you've only done this in storyboard, and it's a dynamic table, the table looks to your numberOfRowsInSection method to see if it should be populating the table or not. If this is 0, then you'll get no rows no matter what you put into the storyboard.
Also, if you've got a cell identifier of cell in your cellForRowAtIndexPath, but you haven't identified your storyboard cell as cell, then you'll still get blank cells.
Furthermore, if you have implemented these two methods correctly, you need to ensure that this table is hooked up to that class as it's dataSource, either via storyboard or programatically.
But these are all just guesses because I would need to see code to figure it out.
If you are using a UITableViewController, have you changed the cells to static?
You said you don't have any custom code other than what Xcode provides. That is your problem.
You need to implement the UITableViewDataSource methods in order to install your data into your table view. Xcode does not do that. The code Xcode puts into your view controller tells the table view that there is no data. You need to report that there is at least 1 section, and at least 1 row in that section. You then need to write code for cellForRowAtIndexPath that installs data from your model into your cells.
Nikita lists 2 of the 3 methods that you must implement before you table view will do anything.

How to create a view for settings of my iPhone apps in Xcode storyboard

I am new in iOS programming and I would like to create I view for the settings of my app that looks like iPhone's one (like in the picture). Some of rows will call other views when taped and other will not.
What is the best way to do that? I thought about TableView with prototype cells, but is there a best way to do it? or a best-practice for what I want to do? Or maybe a tutorial online?
The fast way in Interface Builder:
Use a UITableViewController, make it STATIC and use the GROUPED style (all in IB).
You can setup the cells to show disclosure indicators (or not) in IB also.
You can segue directly from the rows or the UITableViewController to where you want to go.
If you segue from the UITableViewController, implement the "didSelectRowForIndexPath" method and call "performSegueWithIdentifier" accordingly.
A structure like this is best by UITableView.
First you select how many sections you want, and customize each section with a data structure that you have to be filled with (Probably an array.)
Then you fill up each rows inside
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method, and call your value from the array/dictionary that you have.
for going to a next view when clicked upon
Use the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Hope this helps
The best way to do that is using static UITableViewCell.
See UITableView Programming.
The optimal solution here is undoubtedly UITableView. This is because firstly, you have the need to display a list of options that would have external links to other pages and UITableView is designed and used for this purpose.
In an addition to that, if you want, you can also expand and collapse the rows of your parent TableView into a Child TableView i.e a UITableView as a subview of its parent UITableView.
Put up a UITableView and populate it with UITableViewCell. That will be just fine with the requirement you have.
Hope this helps.

Why can't I change the custom class of my UITableView?

Apologies if this question is a little basic but I've spent several days trying to understand the root cause of this problem without any success.
I am working on an app which relies heavily on UITableView objects. I can successfully use a UITableViewController object and display information in a table but I need to be able to have multiple tables on screen citing data from multiple sources and the UITableViewController seems to be too limited.
I would like to be able to place multiple UITableView objects with the storyboard then create custom class files which manage the tables. Unfortunately when I've tried this, XCODE doesn't let me select these custom classes to manage the tables.
Although I've found some potential workarounds online I want to understand why selecting a new class to govern a table view is not possible.
[I wanted to post images but apparently I can´t until I have a better reputation...]
It depends on exactly what you did. But, you should really take a different approach:
If you can, use a single table view with multiple sections (with headers / footers).
If you can't do that, create a separate table view controller and table view for each section of information that you want. Then, your 'main' view controller should act as the parent and add all of the other table view controllers as children (addChildViewController:) and their views as subviews. This approach will keep your code segregated and organised rather than trying to have one controller manage many disparate views.
.h
{
UITableView *objlefttableview;
UITableView *objrighttableview;
}
.m
viewdidload
{
if(!objlefttableview)
objlefttableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 87, 227, 681) style:UITableViewStylePlain];
if(!objrighttableview)
objrighttableview=[[UITableView alloc]initWithFrame:CGRectMake(227, 87, 263, 681) style:UITableViewStylePlain];
[objlefttableview registerNib:[UINib nibWithNibName:#"View" bundle:Nil] forCellReuseIdentifier:#"leftCell"];
[objrighttableview registerNib:[UINib nibWithNibName:#"ViewR" bundle:Nil] forCellReuseIdentifier:#"rightCell"];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self->objlefttableview==tableView)
{
}
else
{
}
}
so what i just did is i created two tableview objects and then i gave two different custom cell to both of them
If u need more help in this approach do ask
The problem was that where as the UITableViewController object is by default the UITableView delegate and it's datasource, a UIView is not even if it inherits from UITableViewController. I hadn’t specified that and it seems that neither 1 nor multiple tables could function as they had no class governing them set to be delegate and data source.
By specifying in the ViewController’s .h file that it was also the delegate and datasource for the UITableView like below (the delegate and datasource commands should be surrounded by triangle brackets but they aren't displayed on this for some reason):
#interface DHViewController : UIViewController [UITableViewDataSource, UITableViewDelegate]
and in the .m file’s viewDidLoad method specify that it was the data source and delegate for both tableViews like so:
self.tableAnswers.delegate =self;
self.tableAnswers.dataSource = self;
self.tableQuestions.delegate =self;
self.tableQuestions.dataSource = self;
and implementing the necessary methods in the .m file:
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
…both tables can be independently managed and displayed on the same screen.
Thanks a lot to all for your help!
FYI (I think I will still go for #Wain ’s idea of having a single table with section specific content/behaviour - it seems much neater).
1) Add UITableView for your storyboard.
2) Set delegate and data source.
3) Create Outlets (properties in your class) for those tableView's
Then you can work with thouse table views. For example, place label on it, and change it text dynamically in your programm.
Cheers :)

UItableview shared view

I'd like to know if someone there in the community has ever implemented 2 UItableView in on single view, I've searched a lot trough google but i'm not sure if I'm using the correct words. What I need is lo look like as the Facebook menu where shows 2 table views, here is an screenshot of my idea. Any ideas/tutorials/blogs you can provide me will be useful, Thanks a lot!
http://a1.mzstatic.com/us/r1000/119/Purple/eb/62/0a/mzl.uvhmahke.320x480-75.jpg
UITableView is simply a subclass of UIScrollView, which is a subclass of UIView, so, yes, you should be able to have more than one tableView in a single view. The only 'gotcha' with this is that your delegate and datasource callback methods for the table views need to either be broken out explicitly in each method (using if(tableView.tag == 0) or something) or either have completely different objects be the datasource and delegate callback methods. The tableviews don't care where they are located.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(tableView.tag == 0){
//do something for first tableView
}
else{
//do something for other tableView
}
return cell;
}
The image you posted does not have two tableViews in a single view. It looks like there are two tableViews in two separate views, which would more than likely have completely different delegate and datasources.

UIButton grouped Buttons

I'm trying to create a button set up exactly like this:
How would I do this? Can someone show me the code? Is there a way to "Group" UIButtons like this?
You'll want to use a UITableViewController with the sections set to be UITableViewStyleGrouped.
Each of the groups is a section, so you'll want to return how many sections you have with - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView.
For every section, you want to specify how many rows there are with - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section.
You'll want to customize each cell with - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath (which, by the way, tells you which section's particular row you're modifying in the indexPath variable).
Finally, you'll want to handle the row click in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, using the pattern XCode provides for you:
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Hope this helps!
That's a one-group UITableView with two rows (cells). The table style is UITableViewStyleGrouped. I'd recommend responding to selection of the cell using the delegate's –tableView:didSelectRowAtIndexPath: method as opposed to using UIButtons within the cell -- much nicer visual effect.
You can't group uibuttons like that. You can achieve this look-and-feel several ways, the most elegant is to use the grouped style uitableview.
However if you would want your buttons only to look like this, but not exactly like this, then you could also specify images for you buttons. Uglier way to do it, however much simpler ...

Resources