Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2010, 05:42 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
TommyTheCat is on a distinguished road
Default Managing links in uiwebview

Hello
Is there a way to activate functions by tapping links on the uiwebview?
I mean i have a viewController which displays a simple html with few links. I'd like it to execute a function depending on the choosen link.
Thanks in advance.
TommyTheCat is offline   Reply With Quote
Old 07-16-2010, 06:02 PM   #2 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

Take a look at the UIWebViewDelegate method:
Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
It's called when a web view is to load something. So you can catch link clicks there, get info about the requests (like URL info), and take the desired action.
__________________
appz
refreshe is offline   Reply With Quote
Old 07-16-2010, 06:06 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
TommyTheCat is on a distinguished road
Default

Thank you kind sir
TommyTheCat is offline   Reply With Quote
Old 07-16-2010, 06:08 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 4
GreatWizard is on a distinguished road
Default

Look at the UIWebView delegate documentation. There are functions in it specifically for that, like shouldstartloadwithrequest or
GreatWizard is offline   Reply With Quote
Old 07-16-2010, 06:31 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
TommyTheCat is on a distinguished road
Default

Ok i looked into the delegate . I can catch a tapped link when it happens with the uinavigationtype. Also i assume that NSURLRequest should be different for each of the links.
I do it like this:
Code:
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
And apparently I'm doing it wrong, because all of the links have the same urlString. Any suggestions?
TommyTheCat is offline   Reply With Quote
Old 07-16-2010, 06:57 PM   #6 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

What do your links look like? Are they custom or actual web links? Look into the NSURL documentation as absoluteString might not be returning what you expect in relation to the URLs you're using.

I've dabbled in this before using custom links. for example something like: <a href="twitter:username1">... And if I remember correctly, I've id'd the URLs using the scheme and resourceSpecifier NSURL properties. But there are a lot of other NSURL properties you can use depending on how you're defining the embedded links.
__________________
appz
refreshe is offline   Reply With Quote
Reply

Bookmarks

Tags
link, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 333
14 members and 319 guests
akphyo, alexP, appservice, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, mariano_donati, ohmniac, Paul Slocum, PavelSea, Rudy, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0