0

I have apps on iTunes that use a ViewController as an expandable/zoomable ScrollView with a programmatically added button and action to that button. I am currently updating the app and have switched from building the app using XIBs to using the Storyboard. Both versions 1.0 and this 2.0 version are being built with the same xCode 4.6 platform. I have found some code isn't working the same in several areas and have found work arounds for most, but not for the action to this button. I am trying to add an action programmatically to a button on the ViewController that is programmed. the code that worked in V1.0 is not working with Storyboard. I do not remember using ARC in the V1.0 so I don't know if that is the reason. I would appreciate any help on this matter.

Clearly I am not a professional programmer, so it would help to be as clear as possible. Thank You.

Goal: I am simply trying to get the ScrollingViewController to Pop Back to the MainViewController or back to the previous VC using the button that is added to the View that is called BackButton.png

Here is my code:

@interface ZoomingScrollView : UIViewController
{   
IBOutlet UIScrollView *scroller;
IBOutlet UIScrollView *imgView;
IBOutlet UIButton *myButton;  
}
@property (nonatomic, retain) UIScrollView *scroller;
@property (nonatomic, retain) UIScrollView *imgView;
@property (nonatomic, retain) UIButton *myButton;


@end

@implementation
-(void) loadView{
//Image View Scrollable
UIImageView *imgView =[[[UIImageView alloc]initWithImage:[UIImage        imageNamed:@"ZoomingImage.png"]]autorelease];
imgView.tag = 100;
UIScrollView *scroller = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
scroller.delegate = self;
scroller.minimumZoomScale = 0.25;
scroller.maximumZoomScale = 3.0;
scroller.bounces=NO;
scroller.showsHorizontalScrollIndicator=YES;
scroller.showsVerticalScrollIndicator=YES;
scroller.contentSize = imgView.frame.size;
scroller.contentOffset =CGPointMake((imgView.frame.size.width-1024)/2, (imgView.frame.size.height-768)/2);

[scroller addSubview:imgView];
self.view = scroller;


//Button Controls
UIButton *myButton=[UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(0, 20, 60, 40);
[myButton setTitle:@"goBack" forState:UIControlStateNormal];
[myButton setBackgroundImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];      
}

-(UIView*) viewForZoomingInScrollView: (UIScrollView *) scrollView{
return [self.view viewWithTag:100];
}

Thanks again.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
  • can you explain in details what exactly is not working? – kap Dec 20 '13 at 14:29
  • Yes, When I Run the app in the Simulator, the VC comes up as expected, scrolls and zooms as expected, and the Button shows in the upper left corner as expected. When I tap on the programmed "BackButton" the app crashes and I get this in the DebugConsole. – user3122899 Dec 20 '13 at 14:55
  • ZoomingScrollView goBack:]: unrecognized selector sent to instance 0x9a33e50 2013-12-20 15:53:35.626 ScrollableViewApp[1467:14003] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ZoomingScrollView goBack:]: unrecognized selector sent to instance 0x9a33e50' *** First throw call stack: (0x1bfd012 0x15aae7e 0x1c884bd 0x1becbbc 0x1bec94e 0x15be705 0x4f22c0 0x4f2258 0x5b3021 0x5b357f 0x5b26e8 0x7b61d3 0x1bc5afe 0x1bc5a3d 0x1ba37c2 0x1ba2f44 0x1ba2e1b 0x2a677e3 0x2a67668 0x4eeffc 0x25c2 0x24f5 0x1) libc++abi.dylib: terminate called throwing an exception (lldb) – user3122899 Dec 20 '13 at 14:57

1 Answers1

0

Can you add the code for goback: method, which would be like

- (void)goBack:(id)sender
{
[self.navigationalController popViewControllerAnimated:YES];
}
MetalJr
  • 302
  • 4
  • 14
  • Hi Gautham, Thank you for your response. Unfortunately that didn't work. My end goal was to have a zooming scrollview within a VC that would pop back to the original VC, no matter what I did my older code wasn't working. I decided to set the Scrollview and button within Storyboard and used slightly different code. For anyone looking to have a ZOOMING SCROLLVIEW WITHIN A VIEW CONTROLLER, this code should work perfectly. Ugh… for some reason it won't let me post the code. – user3122899 Dec 22 '13 at 05:11
  • Hmmm.. :( can you tell me what is the error displayed after adding goBack method.? – MetalJr Dec 23 '13 at 05:10