Available links in UITableView that open Safari

I am working on an iPhone application and want you to be able to click the link that is in the UITableView. When the link and only the link is selected, I want the Safari application to be open for the selected link. Any suggestions on how to do this? Many thanks!

+4
source share
3 answers

There are several solutions to your problem.

If the links are the only object in the cell, you can simply call the didSelectRowAtIndexPath:(NSIndexPath *)indexPath UITableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath to collect the link from your table data array and then use

 [[UIApplication sharedApplication] openURL:myURL]; 

to open the URL.

Alternatively, you can create your own subclass of UITableCell , which contains a custom button (instead of a rounded right button) that has no image or background (text only), so that it looks like a link (you can even color the text blue, and emphasize this ...). When the user clicks the button, the handler function then calls the same openURL function as above.

The above method works best if you have multiple elements in each cell (so you need to create a custom cell ...

+4
source

A naive approach would be to embed a tiny UIWebView in every cell. UIWebView has a delegate that lets you know when a link is clicked that you can implement to launch Safari or switch to a new controller that hosts the full UIWebView screen.

This approach may be too resource intensive, and I have not tried it myself, but if it works, it will offer more flexibility. I would like to know the results if you try.

To run the link in safari, use:

 NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com"]; if (![[UIApplication sharedApplication] openURL:url]) { NSLog(@"%@%@", @"Failed to open url:", [url description]); } 
0
source

Is the link in its line in a UITableView? If so, then you can process it in the didSelectRowAtIndexPath file when you click the corresponding line.

0
source

Source: https://habr.com/ru/post/1302068/


All Articles