假设您 webView 位于名为 SecondViewController 的视图控制器中,而您的按钮位于名为 FirstViewController 的视图控制器中
1) 在你的SecondViewController.h中创建一个对象
@interface SecondViewController : UIViewController
@property (nonatomic, strong) NSString *whichButtonClicked;
@end
2) 在您的FirstViewController 中导入SecondViewController
#import "SecondViewController.h"
3) 在 FirstViewController.m 中的按钮 IBAction 方法中。使用此代码
- (IBAction) firstButtonClicked
{
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondView"];
secondViewController. whichButtonClicked = @"first"
[self.navigationController pushViewController:secondViewController animated:YES];
}
- (IBAction) secondButtonClicked
{
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondView"];
secondViewController. whichButtonClicked = @"second"
[self.navigationController pushViewController:secondViewController animated:YES];
}
PS 别忘了。在你Storyboard。将 SecondViewController 的 Storyboard ID 设置为 secondView
4) 在您的SecondViewController.m 中使用此代码检查哪个按钮
if ([self.whichButtonClicked isEqualToString:@"first"])
{
///display first web view here
}
else
{
//display second web view here
}
希望对你有帮助