How to make first column in UITableView not scroll horizontally in iPhone Objective-C? - iphone

I have made horizontally scrollable UITableView by adding a table view to a UISrollView and setting the scroll View frame to be what i want to display and making its content size large enough to hold the table inside it. It works perfectly fine. Now what i need to do is freeze the first column (that is not scroll it horizontally) but remaining table should horizontally.
I thought of doing this. Have a table view A and a UiScrollview containing a table view B aligned. And populate the first column data in table A and populate the remaining columns data in table B. This i feel should work for horizontal scrolling but then it wont have proper vertical scrolling as in the vertical scrolling wont be aligned. So the solution to this mite be to relatively scrolling table A vertically when table B is scrolled vertically and vice versa. But i am not how would i implement this. Any ideas.
Or is there an easier way of doing this.
Thanks
AJ

use two different tableviews. one inside scrollviw and the other outside it. then try using scrollview delegates to scroll through both tableviews simultaneously

Presumably in your cellForRowAtIndexPath method you can say something like
if(indexPath.row == 0)
{
//do not allow horizontal scrolling
}
else
{
//do allow it
}
Sorry for the pseudocode, I haven't seen your exact code so I can't comment on it myself, but that's the general idea.

Related

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.

How to implement smooth scrolling using both a UIScrollView and an UITableView?

Is is possible to implement smooth scrolling using both a UIScrollView and placing a UITableView at somewhere starting in the middle of the screen? The UIScrollView contentSize is elongated to accomodate the additional height of the UITableView. The UITableView should be able to contain unlimited and unknown number of rows. Scrolling the entire view downwards will cause the upper non-tableview portion to first disappear and then it scrolls down just like a regular table view.
Put it in another way, I'd like to implement a table with some fixed content before the top row. Think of it like a "header area" for the tables, scrolls up and giving way to the entire table rows.
I probably know that I can implement a TableView and programatically make the first row to contain some fixed images. In this way, it will work as expected. But which is easier to implement?
You really don't want to put the table in a scroll view. When the user scrolls on the table it will not move the underlying scrollview so you won't get the effect you are looking for.
Implement viewForHeaderInSection instead and pass in the view you want to display above the first row, or set tableViewHeader.

iPhone: How to Place a Scrollview Inside of Tableview Cell

I want to put a scroll view inside of the table view cell. I have a number of buttons in one cell of table view and I need to scroll that cell to show the appropriate button.
If you want to use a vertical scroll view then I wouldn't suggest you doing it because, as TechZen wrote, there will be a mess in this case.
If you want the inner scroll view to scroll horizontally then it might be achieved by 2 ways:
Implement a custom table view cell that will include a scroll view inside it.
Add a scroll view as a sub-view to your cell that you will return from tableView:cellForRowAtIndexPath: method.
I suggest you to use the second approach.
There are plenty of examples online. Usually the sub-views are labels or image views, but it is not complicated at all to add a scroll view instead...
I don't think you can do this. It would require nesting of scrollviews which isn't really supported.
Even if it was, it would be very difficult for a user to know which scrollview they were hitting with their pudgy finger. Remember, you don't have the one pixel precision of a mouse on the iPhone. You have an area of at least 15x15 pixels. You don't have a scroll bar but instead just drags anywhere on the screen.
Instead, you should use a master-detail pattern. Selecting the cell in the tableview pushes a detail view which has the scroll view with all the buttons.
Why do you want to do it like this?
I think the best idea is to draw your table view manually above your uiscrollview. I did it, and it works. It just takes more effort and drawing accuracy. But that takes a lot of time. :)

adding multiple column in UITableView

I have multiple column and row data , i want to place it in table view also i want make it scrollable vertically as well as horizontally . how to do this ? please help...
The UITableView is not meant to be used in a multi column way.
What you can do is to create custom UITableViewCells that look like two or more columns. But that will be just a workaround without the possibility to scroll horizontally.
The other possibility is to implement a UIScrollView. Add a View to the UIScrollView that is wider than the actuall iPhone screen. In this case the user will be able to scroll horizontally. In this case you will in deed not be able to use the predefined API-functionality of the UITableView and you have to render your table on your own.
My library, UIGridView, does what you want.
But it only supports vertical scrolling.
It is built with UITableView, in which UITableViewCell contains many cells inside.
You can try implement your own library, learn UIGridView's code, or use UIGridView.

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.