How do you build a 3 column layout of varying height images for the iphone - iphone

I need to create a screen that scrolls vertically - like the tableview but I need 3 columns and within those 3 columns I need to add images of varying height - so this will not fit into rows that a tableview can provide.
Should I create 3 tableviews and lay them out side by side - or something else. I think I could build this by simply positioning the images using coordinates but I wanted to benefit from methods that the table view can provide.

If you want the columns to act stuck together, so that they all scroll simultaneously, then I think best approach is to use UIScrollView with the images added in the correct placed "by hand." UITableView and friends is not built to handle non-lined up columns.
added If you do use a UIScrollView, and you have a large number of images you want to display (that is, the user can scroll for a long time), then it would be wise to recycle your UIImageView objects that are scrolled off the screen. This is what UITableView does with UITableViewCell objects, and that's why UITableView wins. You can win, too, if you code carefully.

Three table views would work, but in order to keep things neat and from the same datasource, I would consider using a subclassed UIPickerView and the UIPickerViewDelegate/UIPickerViewDataSource.
Particularly necessary methods:
// UIPickerViewDataSource
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:
// UIPickerViewDelegate
– pickerView:rowHeightForComponent:
- pickerView:viewForRow:forComponent:reusingView:

According to my opinion You should have to take three UITableView in xib file and take its IBOutlet then give each UITableView an unique tag and then implement UITableView's Delegate methods and in that Methods Check for Tag and then assign values.
Along With this, the other solution, you can also use UIPickerView and then implement UIPickerView's delegate methods also..
Happy Coding !!!

Related

TableView with different cell types or ScrollView with inner TableViews

I saw many stackoverflow questions, but I could not come to a definite answer.
I need to create the following screen (detailview):
It's wide ScrollView screen which contains among other custom UITableViewCells of different types.
NewsCell and SongCell - are two custom UITableViewCells classes, which appear differently.
How to properly implement such a screen?
Option 1:
Use UITableViewController and UITableVIewCells of different types:PhotoCell, DescriptionCell, NewsCell, SomeTextCell, SongCell.
Option 2:
Use UIScrollViewController, which contains other elements (Image, Labels, UTableView for news and UITableView for songs. (But I read that insert UITableView into UIScrollView it's wrong, because UITableView is subclass of UIScrollView)
Option 3:
Something else.
Waiting for your comments!
Create multiple custom cells and start integrate into your tableview. If you want to show the cells based upon the content you can calculate the internal elements size and take the highest element hight and make the cell height. Now you can observe that cells will display based upon the highest element hight.I think it will full fill your requirement.
If there is a pattern like a header followed by few cells, then you can use sections which is a feature in uitableview.

How to fix the header and first row in a UITableView

I´m new trying to make some apps using objective c, so I´ve an idea using uitableview but I don't imagine how can I get this.
I´m trying to do something like you do in a spreadsheet where you have a fixed header and the first column too
So when scroll the uitableview vertically the header will stay visible at top of the table and rows will change
And finally when you scroll in horizontal direction the first cell of the row will stay visible and will change the header depending of how you scroll the uitableview
I hope you could give me an idea how to get this, because I don't imagine how to do this, also I don´t have a lot of experience with this programming language.
Thanks!
In a non-grouped table, section headers "stick" at the top of the table as the table scrolls. You can provide a custom UIView (or sub-class thereof) for a section header through the delegate method –tableView:viewForHeaderInSection:. This header view could be created on-the-fly programmatically or loaded from a NIB file. Either way, you can have it contain whatever you want, even update it as the app runs (provided you have given yourself access through ivars or class variables to the views contained in your header view.) If you go this route, you'll want to be clever about allocating resources that comprise this view, so that you are not constantly allocating new resources! This delegate method can be called frequently, and on all but the first call you could simply return the previously created (but updated as and if necessary) header view.
UITableView isn't designed to do this, although I am sure you could figure out some way eventually.
My approach would be to use a fixed UIView of some sort (possibly a UILabel, etc) in a UIViewController's nib as the header/locked cell, and add the UITableView under that. You couldn't then use a UITableViewController, but would have to implement the delegate and dataSource methods in your UIViewController, and use a UISwipeGestureRecognizer to pick up the gestures from the tableView and update the other views.
I've done this by adding a UIView that mimics the first cell in my table. In my case I am using a subclass of UITableViewCell, but that is perhaps not relevant. Normally this view is hidden with an alpha of 0.
If you view controller is the delegate of the UITableView then it will also be the delegate for the inherited UIScrollView. So in your view controller you can implement scrollViewDidScroll. When the scrollView's contentOffset is positive I set my custom view's alpha to 1 (I also do some small size tweaks to make sure there is a perfect match), and when the contentOffset returns to 0 or negative, I reset the alpha back to 0.
prepend the first row of data in your array to what ever in the first row is your headings, put the text in bold with attributed text, It wont be sticky but you will have headings...

How To Replicate This User Interface Design?

I want to create a UI like the on in Mint.com app. Is it a UIScrollView with UITableView cells in it?
Notice how each block/cell has multiple data values in it.
This is all about customising the table view and table view cells. The best tutorial I've found is Cocoa with Love: Easy custom UITableView drawing. It's a good place to start.
This is a UITableView with UITableViewStyleGrouped and multiple sections. The spacing between sections appears to be increased from the default value.
The cell backgrounds have a slight gradient added to give them depth. Each section appears to have a different custom layout of labels, and, in the one case, a custom slider-like object. The object on the right is a standard UITableViewCellAccessoryDetailDisclosureButton.
You can achieve similar effects by subclassing UITableViewCell.

Optimizing a UIScrollView with a lot of subviews

I have a UIScrollView that I am using to simulate a UITableView like interaction because rows are a bit more complex than what UITableView has to offer. I have 4 UILables a UIImageView and a UIButton for every row. The end result is a lot of subviews.
Even with only 10 rows,the scroll view that looks fine in the simulator but has a fairly low frame rate on the iPhone 4. This is a resource consumption issue for sure.
Is there a way to optimize the redraw durring scrolling like double buffering?
If not is there another way to get customizable UITableview functionality?
thanks
Does every View have 4xUILabels, a UIImageView and a UIButton?
I would create a nib file with a custom UITableViewCell (You can make those as complex as you want), then you can reuse the cells to help with your performance.
Information on how to do this is here:
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1
I think you probably want to create a custom subclass of a UITableViewCell as the UITableView will handle all the redrawing for you. In a custom UITableViewCell you can add as many subviews as you like.
Take a look at http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html.
UITableViews are subclasses of UIScrollView (or at least conform to their behavior), but you really want to let the iPhone handle the selective drawing/cell reuse for you that the UITableView provides.
You should use UITableView if it does everything you need.
However if your tableview cells are really complicated, or you want to enable paging on the scrollview, you should take a look at the PageContol sample code that Apple provides. In a nutshell, you watch for movement in scrollViewDidScroll: and load new "pages" just before they become visible. This method works very well in practice for arbitrarily long lists of pages.

TableVIew Problem

i i want to activate scrolling vertically through programming for 2 UITableview at sametime?(one table view length 160,another one has 160).is it possible ?In one Viewcontroller's view i have scrollview, on that i have two tableviews(instead of one,like two column)..how can i scroll vertically both at same time?any help please?
If you want to implement 2 separated and round-rected columns then it might make some sense.
In any other case just use one UITableView and separate each cell visually (the left half will display the data for the first column and the right - for the second).
If you still want to have 2 separate table views and have them both scrolled simultaneously then get rid of the containing scroll view and implement the UIScrollViewDelegate as was already suggested.
Something like this:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.leftTableView.contentOffset = scrollView.contentOffset;
self.rightTableView.contentOffset = scrollView.contentOffset;
}
I think that this code should do the magic...
Don't forget to set the view controller to be the delegate of both table views.
I don't really get it but a table View on top of a scroll View will create problems. Because, when users scroll, both of the views will try to get the interaction of the user, and they can take turn to get that interaction randomly.
Can you post a picture, or clearer description of what you want?
If your next question is "how do I make the scroll views stay at the same offset?" -- i.e. you want them to sync vertically -- than I would advise that you abandon the idea of using two UITableViews.
Instead, define a two-column UITableViewCell, which can easily be done with Interface Builder, and use that to give the appearance of two columns.
I think that doing away with neither UITableView’s userInteractionEnabled set to YES, and implementing your own touchesMoved:withEvent: method (maybe also try UIGestureRecognizers) would prove fruitful.
I am guessing that these UITableViews are not used to show plain tabular data but images or other content, and have a different interaction paradigm (e.g., when the two fingers slide separately the two table views scroll in separate velocity & direction). If that is the case you might ultimately want to use custom controls.
But if you just want a 2-column UITableView then as Jonathan said, simply use a two-column cell.