Pergunta

Hi friends,
I am getting data from server when user post a link on his timeline am displaying like this but my requirement is when i click Title then it will open browser. How can i do this?

when i click **Bollywood.com:Entertainment news,movie,music and fashion rev**

Foi útil?

Solução

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];

Will open a URL by the Application defined for the scheme. http has Safari as default (I guess)

To open it in the App itself create a ViewController + xib, add a UIWebView to your View & Buttons to get back to the app.

Then you can create an instance of your new ViewController and present it with

[self presentViewController:WebVC animated:YES completion:^(void){
    [[WebVC MyWebView] loadRequest: [NSMutableURLRequest requestWithURL:[NSURL URLWithString: @"http://stackoverflow.com"]];
}];

e.g.

To make it even easier you could add a function to your ViewController like this one

-(void) LoadUrlFromString: (NSString *)url{
[self.MyWebView loadRequest: [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]]];
}

and then just do as before but call

[WebVC LoadUrlFromString:@"http://stackoverflow.com"]; 

on completition

Outras dicas

You can use TTTAttributedlabel

 TTTAttributedlabel *title_lbl = [TTTAttributedlabel alloc]init] //Make it an instance of TTTAttributed label what you are using for displaying the Title.

 NSRange range = [title_lbl.text rangeOfString:"YOUR_TILE_HERE (Latest bollywod and hollywood.....")"];
 [title_lbl addLinkToURL:[NSURL URLWithString:@"YOUR_URL_HERE (www.bollywood.com)"] withRange:range];
 title_lbl.delegate = self;

And for onlcick method

- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url
{
  NSlog("%@",label.text);
  [UIApplication sharedApplication] openURL:url];
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top