Reputation: 2818
Suppose I have an app with 3 buttons each opening 3 different UIWebView view controllers. Instead of having 3 separate view controllers for each button, I want to have 1 UIWebView view controllers and depending on the button that is pressed, that is what will show on the UIWebView.
This is just an example of what I am talking about
firstViewController
Button 1 opens Yahoo
Button 2 opens Google
Button 3 opens Bing
secondViewController
if button1 is pressed, show Yahoo on the UIWebView if button2 is pressed, show google on the UIWebView if button3 is pressed, show bing o the UIWebView
How do I come up with this?
Upvotes: 0
Views: 925
Reputation: 82756
in iOS each object contains own tags
if you are interest use tags else other options.
assume that your button1.tag=10, button2.tag=20 and button3.tag=30
set the global string for in .h file
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;
}
// this is your second view controller
@interface secondViewController : UIViewController
@property (nonatomic, strong) NSString *buttontype;
@property (strong, nonatomic) IBOutlet UIWebView *webview;
@end
in your .m file 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];
}
just like follow the another two condition for bing and yahoo ....
Upvotes: 1
Reputation: 856
Button 1 opens Yahoo
In its action write:
[webView loadRequest:YOUR REQUEST_YAHOO];
// reload your view
Button 2 opens Google
In its action write:
[webView loadRequest:YOUR REQUEST_GOOGLE];
// reload your view
Button 3 opens Bing
In its action write:
[webView loadRequest:YOUR REQUEST_Bing];
// reload your view
For reload your view you can use:
[self.view setNeedsDisplay]; //such methods
Upvotes: 0