Заставить UIBarButtonItem открыть ссылку в сафари? - PullRequest
0 голосов
/ 18 августа 2011

Здравствуйте, я новичок в разработке для iPhone, поэтому я был бы признателен за помощь здесь. Я бы хотел, чтобы мой UIBarButton закрыл приложение и затем открыл ссылку в сафари.

in the .h file

#import <UIKit/UIKit.h>


@interface MoviesViewController : UIViewController {

    IBOutlet UIBarButtonItem *rightButton_;


}

- (void) goSafari;


@end

in the .m file

    #import "MoviesViewController.h"


@implementation MoviesViewController


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];    

    rightButton_ = [[[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStyleBordered target:self action:@selector(goSafari)]autorelease];


}

- (void) goSafari {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];

}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

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


- (void)dealloc {
    [super dealloc];
}


@end

1 Ответ

2 голосов
/ 19 августа 2011

Ваша реализация метода "gosafari" имеет неправильное название - должно быть "goSafari", чтобы соответствовать указанному селектору и прототипу метода.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...