Xcode - When to use a UIView or a UITableView? - objective-c

If I want to list some items from a database, do I need to add a UIView and a UITableView to my ViewController? or just add the UITableView to my ViewController?

You must already be having a UIView as part of your ViewController, Just add UITableView as a subview to your UIView.
The UIView of a ViewController can be accessed as [self.view];. So what you need to do is [self.view addSubview:yourTableView];. Using setFrame properly sets it in the x,y,width,height that you need.

Just add the UITableView cause you are already have a UIView, Please check this tutorial on how to use UITableView.

its just depend on your project layout if you want to add tableview then you can use predefined function like didselectrow,moverow,editingrow,willdisplay etc...it totally depend on your need and layout specification and last thing tableview is better than using view instead on another view.

Related

UITableView inside UIScrollview Horizontal Paging Programatically

Good day,
I have a question about programmatically adding UITableView inside UIScrollView. The structure is like that:
UIView
UIScrollView
UIView(contentView)
UIImageView
UITableView
How can I add the UITableView programmatically inside UIScrollView so when I scroll horizontally to switch between UIImageView and UITableView. Note I am using Autolayout so I need to add constraints also. If it is going to be easier with storyboard please let me know how to do it with storyboard instead of programmatically
I used SwipeView it is pretty easy to use 5 minutes installation and did what I was looking for.

Combined UITableView with other elements - how to create and use the view?

Ive a project close to doing everything I need it to do. Its got a Main page which has four buttons that allow you to choose an option. Then a tableview page is launched from those options and displays a parsed XML feed from a website. You can then select one of the options in the table to see a detail view of the item, enquire about it, etc.
My problem is I need to add more elements to the TableViewController page, other than the tableview itself. I want a customized back button (not the navigation controller standard) plus some labels, images, etc.
In the TableViewController xib, the tableview itself fills the page. I cant resize it to add more elements above it. I can add a 'view' window seemingly above the tableview and put things in it. But it seems to add the view to the tableview. This means that when I scroll the table, the other elements like new back button, scroll away as part of the table.
So I'm led to wonder whether I need this page not to be a tableviewcontroller, but a viewcontroller, with a tableview inside it, as well as my other view with buttons, etc. Is that the right way to go? But if thats the case, then how do I instantiate the tableviewcontroller within code? Because my page will not be of that type anymore - it will be just a viewcontroller. But in code Im making a tableviewcontroller .. slightly scared by that route tbh.
Any illumination on this would be much appreciated, as various searches have left me none the wiser. Thanks.
To customize it, this is the way to go:
Change your class to be a view controller instead, which implements the TableViewDelegate and TableViewData Source protocols.
In the view didLoad of you controller, create the table view, set its delegate, data source, and any other properties you wish and add it as a subview to your view.
tableView = [[[UITableView alloc] init] autorelease];
tableView.delegate = self;
tableView.dataSource = self;
// .. Other customization
[self.view addSubview:tableView];
I suggest doing this programatically rather than IB.
Instead of a UITableViewController, you want a UIViewController that has an IBOutlet UITableView. Drag and drop a UITableView component from Storyboard and hook it up, and position it as needed on the screen. This UIViewController should implement the UITableViewDelegate and UITableViewDataSource methods.
Edit: Remember that a UITableViewController is just a subclass of UIViewController so you don't really have to get rid of all your code. :) You only need to make minor tweaks to your header and main file, and change the Storyboard to be a UIViewController instead of UITableViewController as I mentioned above.

UITableView in a UIScrollView - How to make the view scroll, but not the TableView in itself?

Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:
I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?
Possible solutions I've founded today
1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)
2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?
I would ditch the UIScrollView and just use a UITableView. You can add a UIView object as the tableHeaderView of the UITableView just by dragging it in in Interface Builder. Now since everything is part of the UITableView hierarchy, everything will scroll together as expected.
You could also try setting delaysContentTouches to NO on your scrollView. Depending on your setup, this may make the scroll view respond to the touch first instead of the table view.
From Apples UIScrollView Docs:
delaysContentTouches
A Boolean value that determines whether the scroll view delays the
handling of touch-down gestures.
#property(nonatomic) BOOL delaysContentTouches
Discussion
If the value of this property is YES, the scroll view delays handling
the touch-down gesture until it can determine if scrolling is the
intent. If the value is NO , the scroll view immediately calls
touchesShouldBegin:withEvent:inContentView:. The default
value is YES.
You'll have to (as you've mentioned) add the UIView containing the image and buttons to the actual UITableView. Embedding it in the scroll view will produce the undesired behavior that you're seeing.
I would recommend returning the UIView as the header view for the first section of your table view. You can do this by implementing the UITableViewDelegate method:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
If you maintain an IBOutlet to the view containing your image/labels, you can return it here.
this is same demo i hope its helps you from iphone sorce code library
http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html
thank you

UITableView Question?

I have a simple UITableView setup, but I want each item to contain an image. So when you click on an item is goes to a image. How do you think I would do this? I have about 10 items in my list(array) that will in the TableView.
The UITableViewDataSource Protocol is a must read. Once the protocol has properly been implemented, using the tableView:didSelectRowAtIndexPath is your answer. Depending on your implementation requirements, this answer could vary slightly but the protocol remains the solution.
You will need a UITableViewCell subclass.
http://zcentric.com/2008/08/05/custom-uitableviewcell/
This gives you almost what you need.
If you haven't already done so, add a navigation controller to handle switching between the tableview and the image.
Then overwrite the tableview method :didSelectRowAtIndexPath
[self.navigationController pushViewController:theViewControllerContainingTheImage animated:YES];
Arrange the items in the tableview and in the Array
After that use this in the didselectrowAtIndexPath delegate of UITableView
[myImageView setimage:[picArray objectAtIndex:indexpath.row]];

can i create a UIViewController comprised of UITableView and mixing with other UIKits

please patient with my poor english.
I'd bad concept of UIView, UIViewController, UITableView, UITableViewController..
Now I'd created a NavigationController and ViewController with SegmentedControl and I don't know how to add a custom TableView in the ViewController. All the examples I've seen are subclassing a UITableViewController as it is a whole table without other control in between.
Can anyone show me some guideline to get to create a Form's like apps?
Thank you very much.
I am answering my own answer.
UITableView has two properties call headerView and footerView
these two view are able to put in any custom view to display your custom component on the top and foot of the table.