In my app I have a UITableView displaying tweets from a downloaded json file. Many of the tweets contain a link (to Instagram for example). How would I go about making these links open in Safari? What code would I need?
Asked
Active
Viewed 769 times
2 Answers
2
[[UIApplication sharedApplication] openURL:myurl];
Or is your problem elsewhere?
If that doesn't solve the problem, some code would be helpful to show what your table view cells look like.

johnyu
- 2,152
- 1
- 15
- 33
-
i havent attempted to actually make my links open in safari as i have no idea how, where would i imput this code? – rexr Feb 08 '13 at 11:30
0
First of all you will need to detect your links. Is the link part of the tweet string or is it a separate object in an array?
NSString *yourLink = @""; //we will need more detail in your question for this.
Once you have your link you need to store it as an NSURL like so:
NSURL *url = [[NSURL alloc] initWithString:yourLink];
And then you can open this in a browser using:
[[UIApplication sharedApplication] openURL:url];
It would be useful to see what you are displaying in your table. Is it an NSArray from your JSON, or an NSDictionary?

Patrick
- 6,495
- 6
- 51
- 78
-
Based on the above question, I think you should look this (http://stackoverflow.com/a/2620632/1359306) and maybe lecture 6 of http://thenewboston.org/list.php?cat=28 – Patrick Feb 08 '13 at 14:30
-
and i dont actually have a url to input as it comes from the tweets which are always changing?? – rexr Feb 08 '13 at 16:06
-
I think you need to expand your question. Post an example of the data coming in, how you store it and how you currently display it. I think you need to go through each tweet, detect if it has a link and store results in an NSMutableArray where each object contains another array of the tweet and the link (If there is no link it will store a null value). You will then display each object of the NSMutableArray in the table. – Patrick Feb 08 '13 at 16:15