After looking through numerous Stack Overflow posts, I was unable to find a solution to my problem. If I am asking a question that has already been answered elsewhere, kindly give me a nod in the right direction.
And, please, don't be too harsh on me if I might be using the wrong terminology, as I am still kind of new to mobile development.
Problem: All I am trying to do is click a link in a local web page that gets pulled up in a UIWebView. Currently, nothing happens when I click a link, aside from a brief flash of the current page.
This is where I'm at:
1) When the application loads, I show a web view which displays a "local" web page (that's part of my xcode project). So far, so good.
2) When the end user clicks an item (geographical regions in my case, represented by a flag), additional content becomes visible, including a couple of links, leading to "external" web apges, such as wikipedia and a map web site.
3) Most of my little web app is in the web page I show when the application has loaded. I use JavaScript, HTML and CSS to provide most of the functionality (since I already have a web site that does exactly what it is supposed to do).
4) However, being able to link to other web sites from my start page is crucial.
(If you think this is poor design, I'll accept that. Suggestions for better approaches are always welcome; HOWEVER, I do need to solve my current problem before I can restructure my code. Please bear with me.)
Here's the code that brings up the initial web page:
// View Controller.h
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *spfWebView;
#end
// ViewController.m
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize spfWebView;
- (void)viewDidLoad{
[super viewDidLoad];
//Web Site within XCode Project:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"www/index" ofType:#"html"] isDirectory:NO];
//NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ( [data length] > 0 && error == nil ){
[spfWebView loadRequest:request];
}else if (error != nil){
NSLog(#"Error: %#", error);
}
}];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
So in my web page, I am using standard, normal a href links to point to wikipedia, for example, like so (I had to use spaces in the href part to avoid SO from interpreting it as a link, since I only wanted to show you the code for the link):
Wikipedia
And, as I've mentioned, the page just sits there when I click or tap the link. The page seems to reload briefly and flashes on the screen, but that's all I see.
Any ideas anyone?
After additional searching and finally finding some really great information here on SO and a couple of external links, I now see how naive my original question was. It turns out there is more to it than meets the eye.
I wanted a quick fix for a problem that requires a bit more work than I realized.
The most important things I have learned are:
(1) A UIWebView is not necessarily the same as a web browser.
(2) In a UIWebView, you can display web content, yes, but you have to address page clicks separately, within XCode.
(3) If you are planing on running your web app on HTML5, CSS3 and JavaScript, inside a UIWebView, you can do a lot, but you might have to learn about making the UIWebView a delegate to itself, opening additional views, etc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lessons I have learned come primarily from the following sources:
Clicking a link in UIWebView pushes onto the NavigationView stack
iPhone UIWebView - Open new UIWebView Controller from a hyperlink
UIWebView Link Click
Calling methods from links in a UIWebView
Open a link in a UIWebView
Open iOS6 Apple Maps app from a link in a UIWebView
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So right now, I am refactoring my little phone app, but if anyone has some additional insights as far as making UIWebView links work (in an easy and up-to-date manner), please add your comments, and I will try and implement them into this post.
Related
this is my first question here and I was adviced to place this topic here.
I got a responsive website based on the AURA (PI-)theme. For the xs2 breakpoint I do show another slideshow on the homepage, where I have placed an button as call to action (other button type didn't work either)
On older smartphones like iPhone4 and 5 it is working. But on newer device it ain't.
Please take a look onto this test-page.
You can also check within chrome browser emulating such a device. There the click on the "Explore"-button doesn't work either.
Any help is gladly welcome and I appriciate it very much.
Thank you!
It's quite simple. You got a slideshow with a swipe handler which probably sets a preventDefault for swipe and click/tap. If I try to click it on a test device (android 4), it won't work either. But it does work if i hold it down and then press open. So it's not about the z-index (common error) but about the preventDefault. This means you would have to assign the link to the button/s in the slideshow with javascript.
EDIT:
To assign a link to an element using javascript (just javascript, no jquery or any other library), just put something like that into a script tag or javascript file:
document.getElementById("ID-of-your-button").addEventListener("click", function(){window.location.href = "http://link-desti.nation"});
and that should work fine. If there is another problem with it, just write a comment below please. I will reply on it as soon as possible.
P.S.: Sorry for the late edit, I was having hilariously much work on a "do immediately" level the last days.
I am creating UI in Google Sites by inserting a google apps script Gadget. Things work well on my desktop, but when I access the site on my iPhone or iPad, then I get intermittent UI behavior. That is, my buttons or text boxes do not respond every time these are touched.
I have broken this down to the basic code for my script, below, and still see this.
Thanks for your time - Larry King
function doGet() {
var eventApp = UiApp.createApplication();
var eventIDBox = eventApp.createTextBox();
var eventButton = eventApp.createButton("Submit");
var eventLabel = eventApp.createLabel("Welcome").setVisible(false);
var eventHandler = eventApp.createClientHandler().forTargets(eventLabel).setVisible(true);
eventButton.addClickHandler(eventHandler);
eventApp.add(eventIDBox).add(eventButton).add(eventLabel);
return eventApp;
}
This happens because in iOS, the first tap goes in selecting the iFrame housing the UI and the second goes to the actual UI control. This is a known issue and is recorded in Issue 1086. Please star the issue to register your interest for a solution.
I have an iPad app (XCode 4.6, iOS 6.2, Storyboards and ARC). I am trying to localize a UISegmentControl. I already have the translations in MainStoryboard.strings file, and have this code in the controller's viewDidLoad:
// set titles of UISegmentedControls
NSString *resourcePath =[[NSBundle mainBundle] pathForResource:#"MainStoryboard" ofType:#"strings"];
NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[0]"] forSegmentAtIndex:0];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[1]"] forSegmentAtIndex:1];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[2]"] forSegmentAtIndex:2];
The problem is that both resourcePath and resourceDict are nil. How do I get them for the current language, be it en or some other language?
Don't do any of that. You localize the storyboard by editing the .strings file that goes with it for the appropriate language. When iOS displays the view, it'll automatically grab the proper localization and display it.
EDIT: If you want to pull something from the strings file, do something like this:
[[NSBundle mainBundle] localizedStringForKey:#"someKeyHere" value:nil table:#"MainStoryboard"];
Since UISegmentedControls can't have their title localized, I replaced them with RadioButtons I got from GitHub; localized the labels, moved the radio buttons next to them and it works like a champ.
UPDATE One problem - there doesn't appear to be any way to persist the settings from run to run, therefore, this is not going to work. I am now creating my own custom button and emulating a UISegmentedControl. Works with no problems...
I am developing an app which supports Landscape orientation only. It uses an UIImagePickerController to pick images and/or videos from the library. App is functioning fine in iOS-5 or before but it gets crashed when I try to present image picker controller.It gives the following message after crashing:
* Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
As #rocky said you have to add Potrait mode to your application to use UIImagePickerController Like this
or
add this to your landscape only app delegate class
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
and from Mr.Daniel's Answer i found a nice solution for your Landscape only App,
as you need to support only landscape to your application, you just need to add a category for UINavigationController like this
#implementation UINavigationController (LandscapeOnly)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
#end
and add this to your viewControllers, it works for me.
From UIImagePickerController documentation:
Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
You will have to add Portrait mode to your Support interface orientations if you want to use this controller.
I am trying to implement a set of videos ont his app I am developing, but since I am not an experienced developer I came here to as the help of others.
Well, the app is a simple PS3 games database for iPad using splitView. On the Master I have a tableview with the titles and on the details I have the game cover and two buttons: one for the info on the game (that loads another view) and the other one to load a demo video of the respective game.
As you might know, I created an array to store the name of the games, the filename of the cover image and the description.
So, when I click on the master row for, example Assassin´s Creed II, on the detail view will show the corresponding cover and clicking the info button will show me a brief description of the game.
But the problem is that I don´t know how I can add the video the same way I did with the image..
I managed to play the video using the MPMoviePLayerController, but I had to specify the video, but since I am working with storyboard, and working with just the header and implementation files of the master and detail, as far as I know (or I don´t know at all) I can´t use MPMoviePLayerController class to every video.
So, I ask, is it possible to create a video array and work the same way I did with the cover images???
Thank you in advance,
Marco Almeida.
The solution:
NSString *nomeArquivo = [atualJogo movie];
NSString *Arquivo = [nomeArquivo stringByDeletingPathExtension];
NSString *extension = [nomeArquivo pathExtension];
[video loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:Arquivo ofType:extension]isDirectory:NO]]];
Did you try this?
myVideos = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"myvideo_01"],
[UIImage imageNamed:#"myvideo_02"],
[UIImage imageNamed:#"myvideo_03"],
[UIImage imageNamed:#"myvideo_04"],
[UIImage imageNamed:#"myvideo_05"],
nil];