Horizontal scrolling UITableView [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Horizontal UITableView
I need to make a UITableView horizontally scrollable. I have a custom table with width of 600 and as this is too larger. That table needs to be scrollable. How do I do this?

have a look at this https://github.com/alekseyn/EasyTableView
This should solve your problems.

For anyone who runs across this question, contrary to some of the other advice provided, horizontal scrolling of a UITableView is possible and is not a violation of the HIG. If it was, why would Apple provide the ability to scroll horizontally at all?
The way to get this to work correctly is to only set the ContentSize, not the FrameSize. I am a MonoTouch programmer, so I am not sure what the exact equivalent in objective-c is, but the way we address this is to create a custom class inherited from UITableView and override the LayoutSubviews method. In this method, we calculate and set the current ContentSize.
This approach catches all of the potential cases that we have found where the ContentSize could be reset, including rotating the device, scrolling, and zooming.

CGRect frame = tblView.frame;
tblView.transform = CGAffineTransformRotate(stressTblView.transform, M_PI / 2);
tblView.frame = frame;

What you want to do is use a UIScrollView and fill it left-to-right with "cell"-styled views.

I don't think you can make a UITableView scroll horizontally. My suggestion would be to use an UIScrollView. UIScrollView is a super class of UITableView and gives you the scrolling behavior you expect from a UITableView. What you don't get is the table cell management that makes UITableView so convenient. Hence, you have to manage your own content. It is a little more work, but you get more control.

I don't think that scroll horizontally is a good idea and probably violates the Apple's HIG.
Table view should not necessarily provide all the information but rather just some of the most important information, to view the information that requires a lot of space I suggest you do a detail view.

Related

How to auto arrange all sub views?

I have a UITextView at the top of a UIView, below many UIControls are there like buttons, table view... Possibilities are user can give multiple lines in UITextView, in that case I have to expand(increase height) for UITextview to show two lines, If UITextview height increase every other controls should go down accordingly, How to do it in iOS ? I heard android they are auto arranging easily, Is there any way to do like this in iOS?
Where should I concentrate? Any ideas will be helpful. Thanx.
You should use autolayout for achieving this.
raywenderlich autolaout
developer.apple.com
Auto Layout video tutorial
About Cocoa Auto Layout
This tutorial helps you to understand autolayout in a better way.
You could look at auto layout, it's available from ios6 onwards. It will allow you to easily (some even non programmatically) specify constraints to be maintained while the view hierarchy is being displayed. For a good tutorial see this.
If you are working on iOS5 or below I would recommend the following :
I am assuming that all your views are direct children of the textView, even if that isn't the case the grandchildren views (and further ancestors) will move automatically once their parent moves down.
for (UIView* view in yourTextView.subviews)
view.transform = CGAffineTransformMakeTranslation(0,Y_DELTA_VALUE);
//Y_DELTA_VALUE is the amount you want to move the subviews down by, the
//(amount of height the textView increases by)/2

how to set the content size of a scrollView Dynamically

I have a scrollView and on that scrollView, i have many labels and textView along with one tableView. scrollView is working perfectly fine when the no. of rows are less in tablView but if tableView have more number of rows then i am not able to full content and even i am loosing lots of information in tableView because the tableView isn't scrollable. i have added all the lables, textView and tableView as a subview of scrollview. Can anyone help me in that so i can get full tableView and make it proper scrollable.
Here is my code to set the content size of scrollView.
float maxHeight = 0;
for(UIView *v in [self.scrollView subviews]){
if(v.frame.origin.x + v.frame.size.height > maxHeight)
maxHeight = v.frame.origin.x + v.frame.size.height;
}
self.scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, maxHeight+100);
First you'll need to resize your table, so that it fits all the rows (since as you said, it's not scrollable). I believe that doing so will make all your rows to not be reusable, so if it's a big table you may get performance issues. Also be aware of #David H's answer, so if you really want to do this, you might be better of using another UIScrollView instead of the UITableView (it won't bring much benefit either way).
Second, you'll need to move all the views beneath the tableview, so that they won't overlap. An easy way to do this is to have those views put together in a different view, so that you only need to move one view instead (in this case however, you'll also need to resize that view accordingly).
Finally, instead of looping through all the scrollview's subviews, it should be easy enough to keep track of the view that is closest to the bottom (this depends on how you generate and add the views to the scroll view).
A tableview is a scroll view subclass, and generally Apple says adding it to another scroll view will cause problems. That said there are ways to make it work. Search here or on google for terms like "how to put a uitableview in a uiscrollview".
EDIT: to make it not scrollable you could put a transparent view over the table view that stops or eats touch events.
self.scrollingView.contentSize=CGSizeMake(320,372);
Try this.

Can we add a scroll view inside UITableViewCell?

I have requirement where I have to show some images which are differentiated according to Groups they belong to. I have used a table view to view images listed under groups. User has to scroll horizontally to view more images in a particular group.
Can we add a scroll view to tableview row to allow user to scroll list of images horizontally?
I searched a bit, some comments say its not allowed in apple's HIG some comments say
You can add a UIScrollView to a UITableViewCell and as long as you set the contentSize property of the UIScrollView correctly then the UIScrollView will scroll correctly in the horizontal axis
May I get any confirmation on this ??
Or any alternative approach to achieve horizontal and vertical scrolling for different data without using tableview
Yes it is definitively possible and reasonable.
Here is an excellent tutorial by Felipe Laso that explains it step by step:
How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 1
How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 2
BTW, the approach described in that tutorial is way more efficient than adding a UIScrollview to each cell.
Of course you can add scrollView in tableView.
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];
[cell.contentView addSubview:scrollView];
Now you can set properties for scroll view accordingly.
Sure, this is possible. A UIScrollView inside a UITableCellView will work fine - the HIG says no, probably because it'll be hard to use. The user would have to accuratley scroll either up/down, or left/right and it might be annoying. Shouldn't take long to knock together a quick test.
I have an app with 2 scrollviews - one that allows horizontal scroll, and then inside that another scrollview which allows vertical scroll. The idea is that the user can flick up/down a page, then also flick left/right across pages.
It's not that nice to use, but it's what my client wanted ;)
To make a UIScrollView only respond to horizontal or vertical scroll is all about setting the correct contentSize. Hope this is some help.

Recreate UIPickerView with just one row showing

I need a "PickerView", that behaves like a normal UIPickerView, but only shows one row of data and has a custom design.
Something like you see in the image, showing the transition from subview 1 to subview 2. After the user lifts his finger and after the scrolling stops, only one subview will be shown:
IMAGE
So basically a scrollview which:
is endless in both, positive and negative directions by showing the same entries over and over
uses paging across several subviews
only shows one subview when not scrolling, and no more than two subviews when scrolling.
I can get a endless scrollview to work, but not with paging enabled. Paging will always limit my scrolling to the next subview.
So I'm thinking about creating my own UIView subclass which custom scrolling behaviour to mimic a UIPickerView. But before doing so, I wanted to get some opinions about the idea in general. Is creating a custom UIView the right way to go? Anyone has some experience with the expected performace? (There will be timers to handle the scrolling algorithm, which has to be recreated of course... :)
Another approach would be to subclass UIScrolView and implement the paging myself. I know when the scrollView starts decelerating
, so maybe there is a way to overwrite the contentOffset to have it scroll into the right position...?!
Any help is appreciated! Thanks!
Here is a great custom component, which seems to be able to do everything you need:
http://dev.doukasd.com/2011/04/infinite-scrolling-dial-control-for-ios/
It's not endless, but rather a modified UITableView with a huge number of cells.
Would it be feasible to just use a UIPickerView, but clipped to the middle row? You could turn off showsSelectionIndicator to remove the overlay and have the delegate pass back custom row views.

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.