Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable scrolling via IBAction contained in subview
    primarykey
    data
    text
    <p>My iPad app is currently built as such: xml data is pulled from my website and parsed in a View Controller "FishIDView". This view controller has a UIScrollView "scrollView" that has a subview "XMLView" which is a UIView. scrollView is setup so that it scrolls and pages through the XMLViews based on the number of items contained in the XML. For example 12 items = 12 pages, or instances of XMLView. These pages contain photos of individual fish. Each of these pages contain a button that creates a subview of the UIView "XMLView" called "flipView", and displays the subview via the flip from left animated transition. This subview contains information about the pictured fish. flipView has a button that returns the user (flips back) to the fish picture. </p> <p>My problem is that when I'm looking at the flipView (which is a subview of XMLView which is a subview of scrollView), scrolling is still enabled. If I scroll left or right while on flipView, I see the XMLView of the next fish. I want scrolling to be disabled while looking at flipView. </p> <p>Any suggestions on what I can do to send something like a setScrollEnabled:NO command to scrollView (on FishIDView) from the subview?</p> <p><strong>EDIT:</strong></p> <p>So I assume I need to use a protocol and delegate. I thought I could figure it out, but I'm getting caught up on the implementation.</p> <p>In my XMLView.h (leaving out extraneous code):</p> <pre><code>@protocol XMLViewDelegate &lt;NSObject&gt; - (void) stopScrolling; @end @interface XMLView : UIView { ... id secondDelegate; } ... @property (nonatomic, retain) id &lt;XMLViewDelegate&gt; secondDelegate; ... @end </code></pre> <p>Then in my XMLView.m (with the IBAction hooked to a UIButton which works correctly):</p> <pre><code>... @synthesize secondDelegate; ... -(IBAction)goToInfo { //[self newPage]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES]; [self.secondDelegate stopScrolling]; [self addSubview:flipView]; ... NSLog(@"button pressed"); } </code></pre> <p>In FishIDView.h:</p> <pre><code>@interface FishIDView : UIViewController &lt;XMLViewDelegate&gt; </code></pre> <p>FishIDView.m:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [scrollView setScrollEnabled:YES]; XMLView *subsubView = [[XMLView alloc] init]; subsubView.secondDelegate = self; ... } -(void) stopScrolling { [scrollView setScrollEnabled:NO]; NSLog(@"NO more scrolling!!!"); } </code></pre> <p>When I click on my button in XMLView that triggers "goToInfo", the rest of the action happens, but the log "No more scrolling!!" never displays.</p> <p>Did I go about this the wrong way? I'm still trying to figure out delegates, so I may be completely wrong with this methodology.</p> <p><strong>EDIT 2:</strong></p> <p>I've now tried getting rid of the delegate and going what sounds like a more simplistic route, but it's still not working correctly.</p> <p>In XMLView.m:</p> <pre><code>-(IBAction)goToInfo { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES]; //The next 2 lines are what I added ViewController *mainView = [[ViewController alloc] init]; [mainView stopScrolling]; [self addSubview:flipView]; [infoButton setEnabled:FALSE]; [infoButton setHidden:YES]; [title setHidden:YES]; [UIView commitAnimations]; NSLog(@"button pressed"); } </code></pre> <p>Then in FishIDView.h</p> <pre><code>-(void) stopScrolling; </code></pre> <p>FishIDView.m</p> <pre><code>-(void) stopScrolling { [scrollView setScrollEnabled:NO]; NSLog(@"NO more scrolling!!!"); } </code></pre> <p>The "No more scrolling!!!" prints, but scrollView is still scroll enabled! Why would it run the NSLog portion of stopScrolling but not setScrollEnabled:NO? Can anyone help me? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload