We help IT Professionals succeed at work.

Simple Objective C help

Michael Sole
Michael Sole asked
on
I am creating a very simple webView app by following a tutorial. For some reason I can not get my action goToHome to show up when I try to assign it to a button in the xib. Here are the .h and .m files:

.h
//
//  ViewController.h
//  Premiere Orlando
//
//  Created by Michael Sole on 11/2/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UIWebView *webView;
    IBOutlet UIActivityIndicatorView *activityView;
}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityView;

-(IBAction)goforward:(id)sender;
-(IBAction)goback:(id)sender;
-(IBAction)goToHome:(id)sender;

@end

Open in new window

.m:
//
//  ViewController.m
//  Premiere Orlando
//
//  Created by Michael Sole on 11/2/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

@synthesize webView,activityView;

-(IBAction)goforward:(id)sender{
    
    [webView goForward];
}
-(IBAction)goback:(id)sender{
    
    [webView goBack];
    
}
-(IBAction)goToHome:(id)sender{
    
    NSString *myURL = @"http://premierorlando.mobi/index.php";
    NSURL *url = [NSURL URLWithString:myURL];
    NSURLRequest *myRequest = [NSURLRequest requestWithURL:url];
    [webView loadRequest:myRequest];
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

@end

Open in new window

Comment
Watch Question

That looks fine upon first look.  A couple things though:

- You should be releasing your properties, or setting them to nil in your dealloc method.
- Try adding NSLog(@"%@",webView); to your goToHome method to see if the webView is there, or if is simply null.
- Could you attach your project so I could take a look at the IB?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.