0

我有一个视图,里面有 3 个容器视图,其中两个是选择器,最后一个是 2 个按钮。一个按钮打开一个 url,由两个选择器创建,另一个按钮刷新链接。如果两个选择器都返回 (null),则链接有效。如果其中一个选择器返回一个值,并且单击了刷新按钮,则该链接将不再起作用。

    - (void)viewDidLoad
 {
[super viewDidLoad];
// Do any additional setup after loading the view.

[_button_amazon_link setTitle:@"amazon.de" forState:UIControlStateNormal];
[_button_ifixit_link setTitle:@"ifixit.com" forState:UIControlStateNormal];

[self refreshview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void) refreshview{
AppDelegate *appdelegatestrings = (AppDelegate *) [[UIApplication sharedApplication] delegate];

appdelegatestrings.link_amazon = [NSString stringWithFormat:@"http://www.amazon.com/s/field-keywords=%@+%@", appdelegatestrings.model, appdelegatestrings.dead_thing];

appdelegatestrings.link_ifixit = [NSString stringWithFormat:@"http://www.ifixit.com/Device/%@/%@", appdelegatestrings.model, appdelegatestrings.dead_thing];
link_ifixit_ready = appdelegatestrings.link_ifixit;
link_amazon_ready = appdelegatestrings.link_amazon;

}
-(void) openurl : (NSString *)urlstring
{
NSLog(urlstring);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlstring]];
}
- (IBAction)button_amazon_link_clicked:(id)sender {
[self openurl:link_amazon_ready];

}
- (IBAction)button_ifixit_link_clicked:(id)sender {
[self openurl:link_ifixit_ready];
}

- (IBAction)button_refresh:(id)sender {
[self refreshview];
}
4

1 回答 1

0
   -(IBAction)btn_press:(id)sender{
        [[UIApplication sharedApplication] openURL:[NSURL 
URLWithString:@"http://www.ifixit.com/Device/iPhone"]];
    }

这对我有用!!!

于 2013-10-18T10:20:31.700 回答