I am working on an iPhone app, and would like to be able to click on a link that is in UITableView. When the Link, and only the link is selected I want the Safari app to be opened to the selected link. Any suggestions on how to do this? Thanks so much!
There are multiple solutions to your problem.
If the links are the only object in the cell, then you could just make call the didSelectRowAtIndexPath:(NSIndexPath *)indexPath function of UITableView to gather the link from your array of table data, and then use
[[UIApplication sharedApplication] openURL:myURL];
to open the URL.
Alternatively you could create your own UITableCell subclass that contains a custom button (instead of a rounded rect button) that has no image or background (only text) so that it has the appearance of a link (you could even color the text blue, and underline it...). When the user clicks the button, your handler function would then call the same openURL function as above.
The above method works best if you have multiple items in each cell (which is why you would have to create a custom cell...
A naive approach would be to embed a tiny UIWebView into each cell. UIWebView has a delegate that lets you know when a link is clicked which you can implement to launch the Safari or navigate to a new controller hosting a full screen UIWebView.
This approach might be too resource intensive and I haven't tried it myself but if it does work it would offer a lot of flexibility. Would love to know the results if you try it.
To launch a link in safari use:
NSURL *url = [NSURL URLWithString:#"http://stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#", #"Failed to open url:", [url description]);
}
Is the link in its own row in the UITableView? If so, then you can handle it within didSelectRowAtIndexPath when the appropriate row is clicked.
Related
Here we are using UIWebview related application.
while clicking on some links, it's automatically connect(go) to the itunes.
but it's cannot get back to the app after clicking a itunes link (with out clicking on Exit).
My Question is, how can come back to the app after clicking a itunes.
Try this one uiwebview delegate method.
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}
return YES;
}
I usually insert a button next to UIWebView.
Use a new view and insert button in any corner of view and then put your UIWebView, set your uiwebview is not fit to screen so you can push to exit button. When you tap to button than hide your view. ITs usually what i do for such situation, maybe it can help to you
When you click on any link and you now go to at this link of page and if you want to go previous to your application. Generally You can not go Back to your Application because Apple iOS does not provide this types of feature.
I am not sure but It may be possible in JB Device.
you can add custom tool bar at the top of your view and add back button to custom tool bar to come back to your app. Below to custom tool bar add your webview.Hope it will helps you.
If you are loading the webpage with Safri or you are opening iTunes app with custom schema, it is not possible, because you are leaving the app.
But yes you can do this, If you will load that itunes connect link through web view, and there you can place a custom back button to come back to your previous page.
For Example :
UIWebView *webView=[[UIWebView alloc]init];
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.xyz.com"]]];
My app will display some text, and I want to make the hyper-link be able to be clicked. I have some questions about this feature.
How do I parse the text to be aware this is a link?
Once a user click the link, I don't want the OS to switch to Safari and open the link, this is very bad because the user can not go back to my application. So I want to open the link within my application. As soon as the user click the link, my app will present a view modally to display the web content. Any advice would be appreciated.
You probably want to subclass UILabel. When you change the text, have it try to see if the text is a hyperlink, if it is, set it to enable user interaction and change the text color to blue. When the user taps on the link, send a message to the main view controller (Possibly through delegation) to open the link.
to display web content in your app, look into UIWebView.
If your text can be formatted as html with hyperlinks (<a> tags), you could use a UIWebView to display it.
The UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType: method is called when a user taps a link. Usually you would make your controller implement this method, and set the UIWebView's delegate to the controller.
You're going to want to check out a Github project called LRLinkableLabel.
It will auto-detect any URLs that are inside the .text property.
You can use it like so:
LRLinkableLabel *label = [[LRLinkableLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
label.delegate = self;
label.text = #"Check out http://dundermifflin.com to find some great paper deals!";
Then just make sure self implements this method:
- (void) linkableLabel:(LRLinkableLabel *)label clickedButton:(UIButton *)button forURL:(NSURL *)url {
[[UIApplication sharedApplication] openURL:url];
}
You can also use the linkColor and textColor properties to configure the appearance of the label. From this point you can use it just like any other UILabel.
Remember to set the delegate to nil when you're all done to make sure everything is all cleaned up.
Hope this helps.
1) user launch application
2) user press button
3) button loads http://domain.com/mypage/?item=123
How do you trigger http://domain.com/?item=123, without opening the actual page in the browser?
NSURLConnection is the answer.
Not 100% sure of what the question is, but you could use a UIWebView. Load that UIWebView in the app with the URL and you should be good to go.
Hope this helps!
NSString* str = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://domain.com/?item=123"] usedEncoding:NULL error:NULL]
I have used a UIWebView set to "hidden". It probably is not the most efficient way but if you normally use UIWebViews and Interface Builder then it is easy. You can also use the webview delegate methods to watch it.
On second thought - use the NSURL String method above but put it in a new thread.
I have never use youtube api in iPhone ...I tried to use GData but was missed in some steps here are link ans tutorial ....So never implemented it...
Due to which i used RSS feed and load it on tableView ...
and when user click on any row then the actual webPage opens in WebView and user have to click on the video to run it....
But now i don't want this ....
Can anyone provide me a better solution....
Thanks...
As I have given a brief answer here
I am explaining it in detail:
Put a button of same size and without any background image over your webview.
When the user presses this button open a new modal view with only a full screen size webview in it.
Pass the same html string to load the webview (that you were passing in your smaller webview).
Pass the touches programmatically to the webview like:
– (void) touchTheWebViewProgrammatically{
for(UIView* vw in [webView subviews]){
if([vw isKindOfClass:[UIButton Class]])
[vw sendActionsForControlEvents:UIControlEventAllEvents];
}
}
When the user selects some text in UITextView or UIWebView, UIMenuController is shown. Is there any way to access this selected text programmitically?
I need it because I want to add custom item to UIMenuController: 'Search' option which will be intended to search for selected text in database.
Is it possible without using 'Copy' item in order to copy the text to pasteboard and then getting it from UIPasteBoard with the next time? - I am not interested in such workaround.
What I did was to add this method to a UIWebView's category:
- (NSString *)selectedText {
return [self stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
}
After that, I can use [webView selectedText] to access the current selection.
Did you have a look at Apple's documentation.You can use the MenuItems property provided to create your custom UIMenuController.Have a look at the image below
and follow this
link for details.
You can also have a look at the sample code provided by Apple to understand that feature.
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139
In this sample code they have show "Email" in the UIMenuController.
So go ahead and code...All the best...
Cheers
To grab text from a PDF displayed in a UIWebView this will work
-(void)copiedString{
[[UIApplication sharedApplication] sendAction:#selector(copy:) to:nil from:self forEvent:nil];
NSString *copiedString = [UIPasteboard generalPasteboard].string;
NSLog(#"Copied String: %#",copiedString);
}