【发布时间】:2014-07-22 14:07:38
【问题描述】:
在我的应用中,有不同的按钮触发不同的警报视图。每个人都有一个选项来单击指向相同 UIWebView 的“更多信息”。我想在 webview 中加载不同的 url,具体取决于哪个警报将其定向到 webview。 我尝试创建不同的 segue 标识符并附加了该代码。但是 webview 是空白的/不加载 url。有没有办法使用不同的 segue 标识符来完成这项工作?或者有没有更好的方法来做到这一点,我可以对所有警报使用相同的 segue,但仍然在 webview 中加载不同的 url?我如何告诉 webview 加载哪一个?
HomeViewController.m
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1){
if (alertView.tag==1) {
[self moreInfo];
}
}
}
-(void) moreInfo{
[self performSegueWithIdentifier:@"morebainfo" sender:nil];
}
-(void)ftmoreinfo{
[self performSegueWithIdentifier:@"moreftinfo" sender:nil];
}
- (IBAction)bainfo:(id)sender {
UIAlertView *baAlert =[[UIAlertView alloc] initWithTitle:@"Bacillus anthracis"
message:@"This is the message."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"More Information", nil];
baAlert.tag=1;
[baAlert show];
}
- (IBAction)ftinfo:(id)sender {
UIAlertView *ftAlert =[[UIAlertView alloc] initWithTitle:@"Francisella tularensis"
message:@"This is the message."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"More Information", nil];
[ftAlert show];
}
WebViewController.m
@interface MoreInfoViewController ()
@end
@implementation MoreInfoViewController
@synthesize MoreInfoWeb;
@synthesize loadUrl;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString: @"morebainfo"]){
MoreInfoViewController *webview = [segue destinationViewController];
webview.loadUrl = @"http://example.com/";
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *urlToLoad = [NSURL URLWithString:self.loadUrl];
[self.MoreInfoWeb loadRequest:[NSURLRequest requestWithURL:urlToLoad]];
}
【问题讨论】:
-
您是否在 MoreInfoWeb 的 loadUrl 中获得了适当的 url,
-
请发布您的
loadUrl属性标题声明。 -
@Geet 我不确定我是否明白你的意思..
-
@property (strong, nonatomic) NSString *loadUrl;
-
我的意思是尝试在您的 MoreInfoWeb 的 viewDidload 方法方法中放置一个日志 loadUrl 并查看 URL 是否正在传递
标签: ios objective-c xcode uiwebview