2012-07-05 68 views
0

我试图使用一个Web视图,并有三个不同的按钮将您带到此Web视图。每个人都会带你到不同的网站。我已经创建了一个新的webview类,并且在这个类中我有一个方法来设置它将会去的URL。通过赛段传递数据

在原始视图控制器中,我试图发送一个不同的数字通过此方法,但它说没有已知的实例方法。

的代码如下:

方法来设置URL

-(void)setUrlNo:(int)urlNo 
{ 

    if (urlNo == 0) { 

     url = @"http://www.twitter.com/ac3112"; 
    } else if (urlNo == 1) { 
     url = @"http://www.facebook.com/ac3112"; 
    } else if (urlNo == 2) { 
     url = @"http://www.adamcarlin.co.uk"; 

    } 
} 

为赛格瑞方法

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"Twitter"]) 
    { 
     [segue.destinationViewController setUrlNo:1]; 

    }else if ([segue.identifier isEqualToString:@"FB"]) { 
     [segue.destinationViewController setUrlNo:2]; 
    } else { 
     [segue.destinationViewController setUrlNo:3]; 
    } 


} 

回答

1

segue.destinationViewController返回id类型的对象准备。你需要把它投射到您的视图控制器类型来发送消息而不警告:

[(YourViewController *)segue.destinationViewController setUrlNo:1]; 
+0

这似乎并没有解决问题。任何其他想法?或者我只是做错了吗? – 2012-07-05 15:16:08

+0

是否在目标视图控制器的头文件中显示了“ - (void)setUrlNo:(int)urlNo'方法? – FluffulousChimp 2012-07-05 15:24:21

+0

其在头文件中从未提及 – 2012-07-05 15:27:34

0

打开不同的网站,并通过赛格瑞你可以使用基于主视图控制器此方法发送URL。您可以从每个表单元格或按钮创建一个push segue,然后拖动到UIViewController,然后将下面的segue值放在那里,以确保您获得正确的站点/值。

FollowViewController.h

@interface FollowViewController : UIViewController 

@end 

FollowViewController.m赛格瑞方法

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    FollowDetailViewController *webController = [[FollowDetailViewController alloc] init]; 

    if ([[segue identifier] isEqualToString:@"Facebook"]) { // Facebook 
    NSString *[email protected]"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 *[email protected]"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 *[email protected]"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 *[email protected]"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 

祝你好运!