prepareForSegue shows no action on the button

Asked

Viewed 78 times

0

I am relatively new to programming and I have come across an issue that is completely beyond me. Then I have a menu with 6 Uibutton set as Iboutlet in my viewcontroller. Each of these Uibutton calls a specific html internally hosted in the Xcode project. The point is that when using the prepareForSegue the Xcode by and simply ignore any action on the buttons.

This is my role prepareForSegue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender == self.Secretaria){
    uptPiso1WebViewController *vc = (uptPiso1WebViewController*)segue.destinationViewController;
    vc.url=[NSURL URLWithString:[NSURLRequest requestWithURL:[NSURL URLWithString:@"Piso1/Secretaria/vtour/tour.html"]]];

} else if (sender == self.sala){
    uptPiso1WebViewController *vc = (uptPiso1WebViewController*)segue.destinationViewController;
    vc.url=[NSURL URLWithString:[NSURLRequest requestWithURL:[NSURL URLWithString:@"Piso1/Sala105/vtour/tour.html"]]]; 
}
}

Once again I recall my inexperience and I apologise if my question may be too vague, but my last resort was really to try to find a solution here.

Regards

  • Are you using storyboard? the button is there too?

1 answer

1

I created a project to try to simulate what happens with yours, I didn’t have the problems you encountered, however I noticed that when you associate the value to vc.url, I imagine this property is a NSURL, you correctly create a NSURL from a String, but instead of passing a String, you are passing a Nsurlrequest with another URL, this causes a crash in the app by NSInvalidArgumentException.

Just try to use:

vc.url = [NSURL URLWithString:@"Piso1/Secretaria/vtour/tour.html"];

And then in class uptPiso1WebViewController call the following method in webview:

NSURLRequest *request = [NSURLRequest requestWithURL:_url];
[_webview loadRequest:request];

2 other points to improve the code:

  1. Do not compare objects with == as you did with the buttons. Use [sender isEqual:self.Secretaria] https://developer.apple.com/library/iosdocumentation/general/conceptual/CocoaEncyclopedia/Introspection/Introspection.html#//apple_ref/doc/uid/TP40010810-CH9-SW61

  2. Learn to use http://en.wikipedia.org/wiki/Camel_case

Download the project: http://cl.ly/2I2E1B1e0Z33

Browser other questions tagged

You are not signed in. Login or sign up in order to post.