UITableView into a UIScrollView? - iphone

I'm looking to have two views which are part of a constituent set. Data in each view would be best represented in a UITableView. I'd like to then add a gesture to flicker the view off screen and have another similar view brought in, with a page indicator control. My fear is that UITableView intercepts touches and becomes the responder to any such 'flickering' which the UIView might be waiting for. This will directly impede on the usability of the application.
So my question to you usability/UI experts is, is putting a UITableView inside of UIPageControl a poor design choice?

A UITableView is a subclass of UIScrollView. The PageControl sample provided with the iPhone SDK explains nicely how to use a UIScrollView with UIPageControl. Any method which belongs to UIScrollViewDelegate will be called inside your view controller if the view controller implements UITableViewDelegate.
To achieve what you are trying to do, the best approach would be to use UITableView with UIPageControl as explained in the PageControl sample.
Hope that helps!

Related

Touch detection problems with custom View inside UIView NOT UIScrollView

I was googling for a while and I found similar problems but when the custom View is inside a ScrollView, but that is not my case.
I have a custom view that consists of a UILabel behind a UITextField, so I can animate that label later.
The problem is that when I add a View in my ViewController and in the Identity Inspector I set the Class as my custom class, when I use the application the UITextField within my custom view does not receive the touches well and it takes time to gain focus and therefore to open the keyboard. The strange thing is that if I move that same arrangement of views to my main ViewController in Storyboard everything works fine. Why doesn't it do it when I place it using the described method?
I plans to reuse this custom view a lot, so putting logic and views in each ViewController is not an option.
Thanks in advance
Well, the problem was in the constraints of the container UIView. That means, the UIView in my main ViewController. The Height of the UIView was a little bit smaller than the space required for my custom view, so although my custom view seemed to draw correctly, it was not receiving the gestures correctly. The solution was simply increase the height to the correct value occupied by my custom View. Thanks a lot!

UIScroll view + UIView + UITableview question

A UITableview inherits from a UIScrollview. But, if u want a UITableview within a scrollview the best way to do this is embed it in a UIView and add that as a subview to a scrollview.
Is the above correct?
If yes, then UIScrollView inherits from UIView.So finally, when all three are put in the same space how do you know which is calling a particular method.
This is a suddenly-confused-newbie question. So , thanks for your patience! :P
Both UITableView and UIScrollView inherit from UIView. That's not the point. UITableView and UIScrollView as well as UIView are all components. Think of them as building bricks. By them selves they are nothing more but peaces from which you build your application. If you want them to work together and perform tasks you should design and implement controllers (UIViewControllers or UITableViewControllers) that would know how to manage each and every "bricks".
In terms of using and UITableView in the UIScrollView.
Case 1. UITableView needs to be scrollable.
If that's the case then you will have a problem, b/c both UIScrollView and UITableView respond to swipe events, and you will get a collision, and unexpected behavior when scrolling.
Case 2. UITableView does not need to be scrollable.
In this case you should disable scrolling for your UITable and it will work fine.
Generally you can combine "UI elements" such as UITableViews, UIScrollViews and UIViews however you like. But you need to be able to control them through UIViewControllers.

Draggable UIView

I have 4 UIViews inside of a main view controller view. All I need to be able to do is drag the views around the "screen". Is UIScrollView the best option for this, or is there a simpler way?
Apple's Touches sample application contains code that does just this, so you might want to check it out.
UIScrollView should be used for scrolling, not dragging. And the 4 scroll views won't work if they're overlapped so don't even think of using UIScrollView in your case.
A dedicate UIView subclass that overrides -touches*****:withEvent: is needed. See http://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/01-Direct%20Manipulation/ for example.

iPhone SDK view scrolling not rubber banding or using momentum from swipes

I'm having a fundamental problem with getting scrolling to work normally on my iPhone app. I have two views, each created in IB (although I've tried this programmatically and it makes no difference) which scroll very sloppily. Instead of the scrolling that we're used to (which is smooth and continues to scroll and eventually dampen and rubber band at the top/bottom), my scrolling only scrolls as long as my finger is in contact with the view. Swiping down quickly on a view has no more effect than swiping slowly. And when you scroll beyond the top or bottom, the view just stays there scrolled with empty area above/below.
One of my views is a UITableView and the other is a UIScrollView. Both have exactly the same problem and are in different XIBs, coupled to different classes, so this is why I think I'm missing a key concept in general.
My UITableView is a child to a UIView (since there is also a nav bar at the top) with my UIViewController's view connected to the UIView. The referencing outlets datasource and delegate are both hooked to the UITableView. Nothing is subclassed here aside from the ViewController of course which has overrides to populate the table.
In the second instance, I again have a non-subclassed UIView which my UIViewController's view is connected to. I have a subclassed UIScrollView as a child to the UIView and then a have a subclassed UIView (with larger size than the scroll view) as a child to the subclassed UIScrollView. This in itself seems ridiculously complicated to me, but I was not able to get scrolling working at all with fewer than 3 views (again there is a nav bar at the top of the non-subclassed UI-View). I am overriding drawRect: in my UIScrollView, which is putting the content up fine except for this scrolling issue.
Is there something I'm doing wrong organizationally? I've come across many suggestions on stackoverflow and other sites for UIScrollView and none make a difference. And I don't see anyone having scrolling issues with UITableView. I'm not pasting in any code because I would have to post full classes at this point (making the post ridiculously long) and I believe the problems to really lie with the way I'm using IB.
Thanks!!
OK, it turns out that this has nothing to do with UIKit. This code is part of a game I'm developing using cocos2d and that framework is what is causing the problem. For those who are developing on cocos2d, you cannot use FastDirector and expect scrolling to work in UIViews. Just remove any code like [[Director sharedDirector] useFastDirector] and everything will be fine.
Some code might help narrow down your problem.
In the mean time, try creating a new project in Xcode using the 'Navigation-based Application' template and take a look at how the navigation controller is being created in MainWindow.xib. Take a look at how the UITableViewController subclass called 'RootViewController' is defined and how the corresponding xib is setup too. You'll notice there is no UIScrollView explicitly defined anywhere but you get scrolling functionality from the tableview controller 'for free'.
This should give you a pretty good starting point down the right path. I question the need for overriding drawRect: without seeing some code or fully understanding your goal.
Take a look at:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html
http://developer.apple.com/iPhone/library/featuredarticles/ViewControllerPGforiPhoneOS/UsingNavigationControllers/UsingNavigationControllers.html

iPhone: detecting double taps on uiscrollview

Besides subclassing, is there a simple means to detect double taps on a UIImageView within a UIScrollView?
Thanks
I have created ZoomScrollView class (a drop-in subclass of UIScrollView) that can help you intercept any touches from a scroll view, and also handles double-tap zooming out of the box if that's what you want to do.
Grab it at github.com/andreyvit/ScrollingMadness/ (the README contains a long description of two UIScrollView tricks and the reasoning behind them).
Of course, if you did not want to zoom, and just wanted to intercept a double-tap on some inner image view, then subclassing is your friend. (Another way would be to attach a view controller to that image view or one of its parent views inside UIScrollView, then the controller will be part of the responder chain and will be able to handle the touches.)
Looking at UIImageView.h (within the UIKit framework) there are no public delegate methods or other methods that let you know if the image view has been double-tapped. You'll probably have to subclass.
The answer is NO.
http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html
Download the sample code (download link on the top).
See how apple did it.
See you.