Reputation: 471
I have application with 6 buttons on start screen. My problem is that I want to open web page clicking on those buttons. I have a code like this:
- (IBAction) accomodation: (id) sender
{
NSString *webPage1 = [NSString stringWithFormat:@"http://www.google.com"];
NSURL *url = [NSURL URLWithString:webPage1];
// [[UIApplication sharedApplication] openURL:url];
[self beginNavigationWith:2 andTitle:NSLocalizedStringFromTable(@"icn_txt_accomodations", LANGID, nil) andMap:nil andHtml:nil withIdTagsAroundMe: 1 withWeb:url];
}
This is method for initializing one of buttons. After that I have method:
- (void) beginNavigationWith: (int) navID andTitle:(NSString*) aTitle andMap:(NSString*) map andHtml:(NSString*) html withIdTagsAroundMe:(int)id_tags withWeb: (NSURL*) webPage
{
// DIRECT LINK
if (html != nil) {
if ([html hasPrefix:@"{ID}"]) {
NSError *error;
int res_id = [[html substringFromIndex:4] intValue];
NSLog(@"DIRECT ID From start>> %d", res_id);
NSFetchRequest* reqForRestaurant = [[NSFetchRequest alloc] init];
NSEntityDescription *resEntity2 = [NSEntityDescription entityForName:@"Restaurant" inManagedObjectContext:managedObjectContext];
[reqForRestaurant setEntity:resEntity2];
NSString *stringRes = [NSString stringWithFormat:@"res_id.intValue == %d", res_id];
NSPredicate *resPredicate2 = [NSPredicate predicateWithFormat:stringRes];
[reqForRestaurant setPredicate:resPredicate2];
NSArray *array3 = [managedObjectContext executeFetchRequest:reqForRestaurant error:&error];
//NSLog(@">>>> Gallery:%d", [managedObject.res_gallery intValue]);
if (array3 != nil) {
//NSLog(@"Restaurants count=%d", [array2 count]);
if ([array3 count] == 1) {
Restaurant *managedObjectRes = (Restaurant*) [array3 objectAtIndex:0];
RestaurantDetails *details = [[RestaurantDetails alloc] initWithStyle:UITableViewStylePlain];
details.managedObjectContext = self.managedObjectContext;
details.parentID = navID;
details.title = managedObjectRes.res_title;
[details initItemsWithData:managedObjectRes];
[self.navigationController pushViewController:details animated:YES];
}
}
return;
}
}
// STANDARD NAV o puro HTML
NavTableView *navTable = [[NavTableView alloc] initWithStyle:UITableViewStylePlain];
navTable.title = aTitle;
navTable.managedObjectContext = self.managedObjectContext;
navTable.selectQuery = [NSPredicate predicateWithFormat:@"nav_parent_id.intValue == %d", navID]; // parent id == 0 is ROOT
//added for use around me
navTable.id_tags_arroundme = id_tags;
[self.navigationController pushViewController:navTable animated:YES];
if (html != nil) [navTable addHtmlHeader:html];
if (map != nil) [navTable addActiveMap:map];
//WEB PAGE
if ( webPage != nil ) {
NSString *webPage1 = [NSString stringWithFormat:@"http://www.google.com"];
NSURL *url = [NSURL URLWithString:webPage1];
NSLog(@"url = %@",url);
[[UIApplication sharedApplication] openURL:url];
}
}
This way I manage to open web page but in Saffari and I want it inside application. Can someone give me a way to do it.
Thanks.
Upvotes: 2
Views: 9973
Reputation: 22334
You need to use a UIWebView which you can add as a subview to any other view and then call 'loadRequest' on with your URL.
Upvotes: 2