Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add an action programmatically using Storyboard
    primarykey
    data
    text
    <p>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.</p> <p>Clearly I am not a professional programmer, so it would help to be as clear as possible. Thank You.</p> <p>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 </p> <p>Here is my code:</p> <pre><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 </code></pre> <hr> <pre><code>@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]; } </code></pre> <p>Thanks again. </p>
    singulars
    1. This table or related slice is empty.
    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