[英]how to show multiple webviews/URL's under one UiViewController when the user clicks different cells
[英]How to show multiple web view links on Xcode under one UIViewController
假設我有一個帶有3個按鈕的應用程序,每個按鈕都打開3個不同的UIWebView視圖控制器。 而不是每個按鈕有3個單獨的視圖控制器,我要有1個UIWebView視圖控制器,並取決於所按的按鈕,這將顯示在UIWebView上。
這只是我在說的一個例子
firstViewController
按鈕1打開Yahoo
按鈕2打開Google
按鈕3打開Bing
secondViewController
如果按下button1,則在UIWebView上顯示Yahoo;如果按下button2,則在UIWebView上顯示google;如果按下button3,則在UIWebView上顯示
我該怎么想呢?
在iOS中,每個對象都包含自己的tags
如果您有興趣的話)以及其他選項。
假設您的button1.tag = 10,button2.tag = 20和button3.tag = 30
在.h文件中設置全局字符串
NSString *activecheck;
// assign the single method for all buttons in touchup inside method
- (IBAction)button_GetDeals:(UIButton*)sender {
switch (sender.tag)
{
case 10:
activecheck=@"1";
break;
case 20:
activecheck=@"2";
break;
case 30:
activecheck=@"3";
break;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"secondviewcontrolleridentidiername"]) {
secondViewController *destViewController = segue.destinationViewController;
destViewController. buttontype = activecheck;
}
//這是您的第二個視圖控制器
@interface secondViewController : UIViewController
@property (nonatomic, strong) NSString *buttontype;
@property (strong, nonatomic) IBOutlet UIWebView *webview;
@end
在您的.m文件中viewdidload
- (void)viewDidLoad
{
[super viewDidLoad];
if ([buttontype isEqualtoString:@"1"])
NSString *strURL = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webiew loadRequest:urlRequest];
}
就像遵循bing和yahoo的另外兩個條件一樣。
按鈕1打開Yahoo
在其動作中寫道:
[webView loadRequest:YOUR REQUEST_YAHOO];
// reload your view
按鈕2打開Google
在其動作中寫道:
[webView loadRequest:YOUR REQUEST_GOOGLE];
// reload your view
按鈕3打開Bing
在其動作中寫道:
[webView loadRequest:YOUR REQUEST_Bing];
// reload your view
要重新加載視圖,可以使用:
[self.view setNeedsDisplay]; //such methods
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.