您好我是iPhone开发的新手,所以我很感激这里的一些帮助。 我希望我的UIBarButton关闭应用程序,然后在safari中打开一个链接。
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
答案 0 :(得分:2)
您的“gosafari”方法实现标题错误 - 应该是“goSafari”以匹配指定的选择器和方法原型。