-1

In my app I have a UIScrollView and within that I have programmatically created UIImageViews. This is based off the Tab-bar template in Xcode. What I'm trying to do is to change Tabs when a particular image is pressed, and whilst I'm able to register the event as a touch, changing the tabIndex does nothing. Typing in the following code:

    UITabBarController *tab=self.tabBarController;
        if (tab){
            NSLog(@"Good");
        }
        else {
            NSLog(@"No Good");

Always results in No Good being Logged. The code I've written can be seen here, where my UIScrollView is of type ScrollViewer: @implementation scrollViewer - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {

if (!self.dragging) {
    NSLog(@"Recieved Touch!");
    UITouch *aTouch = [touches anyObject];
    MainView *theInstance = [[MainView alloc] init];


     CGPoint point = [aTouch locationInView:self];
        theInstance.ycoord = point.y;
        [theInstance touchHand];
}
    [super touchesEnded: touches withEvent: event];
}

@end

Any help is appreciated thanks!

G4laxy
  • 26
  • 5
  • Ended up using autonomy's answer from another question [Autonomy's Answer Here][1] [1]: http://stackoverflow.com/questions/1207287/whats-the-trick-to-pass-an-event-to-the-next-responder-in-the-responder-chain – G4laxy Aug 13 '12 at 02:54

1 Answers1

0

You never gave us any sample output for:

NSLog(@"Y Coord= %d",adjustedy);

But I will assume the value should cause the switch.

So first you need to log self.tabbarcontroller to be sure it is not nil. If it is ok the system may not want to let you switch inside touch events (it's bad form anyway). I would do the setting as this:

dispatch_async(dispatch_get_main_queue(), ^{ do code here } );

So it runs later.

David H
  • 40,852
  • 12
  • 92
  • 138
  • It seems this method is proving both too difficult and also the method itself is not the best anyway. Do you have any suggestions for a clearer and better method? – G4laxy Aug 13 '12 at 02:00
  • If you think the one line above is too difficult to use, well, I can't think of anything easier. In many many cases you need to defer updating the GUI when you are buried deep in some method. You can learn and use blocks, or there is another way - performSelector:withObject:afterDelay, where the delay is 0 - that will queue a message to a selector on the current thread, which better be the current thread if you're updating the UI. – David H Aug 13 '12 at 11:23