你好我都是iPhone新手,所以我很感謝這裏的幫助。 我想我的UIBarButton關閉應用程序,然後在safari中打開一個鏈接。讓UIBarButtonItem在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
你有什麼問題? – jtbandes
這裏的代碼沒有錯。而且你正在代碼中設置目標/動作,所以它對於IB連接也不是問題。 – FeifanZ
當我點擊按鈕什麼都沒有...... –