iOS - UITableView Pan Gestures - iphone

This may turn out to be 2 questions in one, but I believe solving the first will go most of the way to solving the second.
First, I have created a view in Interface Builder (I know!) and I load the xib file into my view controller in the app delegate. All of this runs smoothly and as expected.
The view consists of 3 table views, two of a similar size and one small one in a corner.
A cell is added to one table view a pan gesture is added to allow movement around the scene.
However, if a cell is moved from it's table view, it appears to go BEHIND the parent view, as per the screenshot below:
The grey line between the two tables is the gray background of the parent view. If the user still has his/her mitts on the cell, they can drag it into view but how can I make it so that all table views are on the same 'layer'?
I.e. so that dragging a cell from one table view to another with show the cell hovering over both views.
This leads me onto my second question, which I will not ask yet as I believe the solution to this will solve my current issue. but I will explain for further clarity.
In my pan gesture, I use a point inside check to see if the cell is within a table view, currently panning a cell from any table makes it print. It is almost like the views take up the whole screen, even though they are sized not to?
All ideas welcome! Thanks!

This was solved by listening for the cell leaving the bounds of the table view, when this happened, I transferred the cell across the table view that it has been dragged to, adding it to the bottom of the list.
Not the most elegant solution and you do lose the touch but it does work,

Related

Is it possible to put one UITableView over another UITableView in InterfaceBuilder?

I know I can use codes to add UITableView one by one.
[self.view addSubview:tableview1];//
[self.view addSubview:tableview2];//
I hope to do the same thing in InterfaceBuilder, when I drag one UITableView onto another one, the new one always pushes the old one to the bottom, rather than just stays over the old one of UITableView.
Welcome any comment
Thanks
If you have a parent view that will contain your tableviews then you shouldn't have any problem. If you're trying to place them directly in a window then I could see a problem. If things aren't lining up the way you want you can always change their position via the Size Inspector or by nudging them with the arrow keys (shift-arrow key moves in 10 pixel increments).
Why anyone would want a tableview on top of another tableview escapes me.
Your parent view should be a subclass of uiviewcontroller and your xib should have the root view as a uiview and not uitableview.
I used two overlapping table views to show two different contents on the same view, which could be toggles using a segment switch. Apparently my client requirements were vague enough that I couldn't just filter out data like how the phone app displays all calls/missed calls list.

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. :)

Looking for a UI library to present Data horizontaly in iOS

Does anyone know of a UI Library for iOS, that acts like a horizontal UITabelView?
I want to scroll cells from right to left and not from up to down.
I had a similar requirement: Horizontally scrolling tables in cells of a normal, vertically scrolling table.
My solution: I put a standard UIiew in the outer table's cell. This view had its transform property set to turn by 90°, serving as a "hinge", turning its contents to the side.
In the hinge view was another UITableView. Since it is contained in the turned view, it appears horizontally on the screen. The cells of this inner table contained another hinge view, turning their contents -90°, back to the upright orientation.
This might sound a little confusing, but it gives you all advantages of table views, in horizontal orientation. It's less confusing if you leave out the outer table view with their cells which are not needed in your case.
Edit: to answer comment
Performance was definitely great. Actually, performance was the major reason to switch to this approach. Table views are especially great for displaying huge data sets, since they only instantiate visible views (cells) and reuse them after being scrolled out. By itself a table view is quite light weight and very optimized for its purpose. My data sets where middle size, I'd say (about 100 items in both dimensions) and scrolling was perfectly smooth.
The other thing besides performance I was concerned about was touch handling. It went out that the table views (which derive from scroll views) always detected the gesture correctly (scrolling a scroll view in a scroll view is not easy to get right). If you swiped vertically the outer table view would handle the events, if you swiped horizontally the inner table gets all the events. I was quite impressed of how well the framework handled this non standard situation.

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.

UITableView Won't Scroll In Certain Conditions

My app has a set of categories. A category can have sub-categories.
DirectoryCategoryController is the first screen, displaying all the top-level categories. Works great. When you tap a cell, if the category selected has sub-categories, I instantiate a new instance of DirectoryCategoryController and push it to display the sub-categories. From there, you tap a sub-category and see the contents.
The problem is that while the top level works fine, when I tap in and see the sub-categories, the table view won't scroll. The search bar takes touches, the table cells take touches but up and down scrolling does not work, like the table view is vertically frozen in space.
If I tap the search bar and hit cancel or if I go into a sub-categories contents and then hit back, the very same table view that didn't scroll works just fine.
Also, if the table view has more items than fit on the screen (about anything bigger than 8 in this layout), everything works.
Very odd problem ; kinda blowing my mind. Any insight?
So, I figured this out and thought I would answer as a reference.
At this point, I think it may be an iPhone OS bug and I'm filing a RADAR.
A UIScrollView, of which UITableView is a subclass, will not attempt to scroll if everything fits on one screen.
In my case, it appears the scroll view thought everything fit (it was very close) but it didn't. Actually, if you removed the UISearchBar from the UITableView, everything would have fit and it wouldn't need to scroll. My guess is that it's incorrectly determining the geometry when the UISearchBar is attached.
Anyway, the work-around was to add this:
[self.tableView setAlwaysBounceVertical:YES];
The odd thing was that when another view was pushed and then popped, the vertical bounce worked fine, furthering my suspicions it's an iPhone bug.
I noticed the same thing when using A UITableView with a UISearchBar as the header view, as configured in Interface Builder in Xcode 4.3.1. In my viewDidLoadMethod, I added the following code and it fixed the problem for me:
self.contactsTable.bounces = YES;
I believe that it's a bug that disables the bounces property, but it can be fixed by re-enabling it.