要打开不同的网站并通过 segue 发送 url,您可以使用基于主视图控制器的此方法。您从每个表格单元格或按钮创建一个 push segue 并拖动到 UIViewController,然后将下面的 segue 值放在那里以确保您获得正确的站点/值。
FollowViewController.h
@interface FollowViewController : UIViewController
@end
FollowViewController.m segue 方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
FollowDetailViewController *webController = [[FollowDetailViewController alloc] init];
if ([[segue identifier] isEqualToString:@"Facebook"]) { // Facebook
NSString *urlstr=@"https://www.facebook.com/";
webController = [segue destinationViewController];
webController.urlstr = urlstr;
webController.title = @"Facebook"; // this sets the title of the next page
}
else if ([[segue identifier] isEqualToString:@"Instagram"]) { // Instagram
NSString *urlstr=@"http://instagram.com/";
webController = [segue destinationViewController];
webController.urlstr = urlstr;
webController.title = @"Instagram"; // this sets the title of the next page
}
else if ([[segue identifier] isEqualToString:@"Twitter"]) { // Twitter
NSString *urlstr=@"https://twitter.com/";
webController = [segue destinationViewController];
webController.urlstr = urlstr;
webController.title = @"Twitter"; // this sets the title of the next page
}
else if ([[segue identifier] isEqualToString:@"YouTube"]) { // YouTube
NSString *urlstr=@"http://www.youtube.com/";
webController = [segue destinationViewController];
webController.urlstr = urlstr;
webController.title = @"YouTube"; // this sets the title of the next page
}
self.title = @"Follow"; // This sets the title of the back button, and the title of this page
}
FollowDetailViewController.h
@interface FollowDetailViewController : UIViewController {
NSString *urlstr;
}
@property (strong, nonatomic) IBOutlet UIWebView *WebView;
@property (strong, nonatomic) NSString *urlstr;
@end
FollowDetailViewController.m
@implementation FollowDetailViewController
@synthesize WebView;
@synthesize urlstr;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:urlstr];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.WebView loadRequest:requestObj];
}
@end
祝你好运!