0

Hi friends My project is based o parsing json datas from url, i have parsed datas and displayed in screen but my problem is, some data i received from json is in the from of link. but when i viewd that in label it looks like normal data, not as link. i need to view it as link. when user clicks the link it has go to that respective webpage in mobile browser. Please help me on how to do it. Here is the code which i tried

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SuccessCell";
    SuccessListCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
    cell.title.text = (NSString *)[array1 objectAtIndex:indexPath.row];
    cell.linklabel.text = (NSString *)[array3 objectAtIndex:indexPath.row];//Here i need show this data as link
    cell.datetime.text = @"Success Story URL(Pictures,Videos,etc.);";
    cell.desc.text = (NSString *)[array11 objectAtIndex:indexPath.row];
    return cell;
}

Please Help me how to do this Thanks in Advance

Naresh
  • 143
  • 3
  • 12
  • 1
    Why you are not using UIButton instead of a UILabel? On press of a button you can directly open that link in browser. – Manthan Feb 20 '14 at 07:59
  • See also: http://stackoverflow.com/questions/13581714/detect-urls-in-uilabel – Amar Feb 20 '14 at 09:04

3 Answers3

3

Use UITextView instead of UILabel if you click on it ,it will call delegate method ,check below code :

    UITextView *textView = [[UITextView alloc] init];
    textView.frame = CGRectMake(10,200, 300, 30);
    textView.scrollEnabled = NO;
    textView.text=@" This is testing url here HTTP://WWW.GOOGLE.COM";
    textView.editable = NO;
    textView.dataDetectorTypes = UIDataDetectorTypeLink;

    textView.delegate = self;
    [self.view addSubview:textView];

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0)
{
    return YES;
}

Note: it support only >= IOS 7.

may it will help you.

happy coding...:)

Dhaval Bhadania
  • 3,090
  • 1
  • 20
  • 35
0

Try the control FancyLabel. It's exactly what you need.

If you get stuck with it, you can try OHAttributedLabel - that's much more simple.

etolstoy
  • 1,798
  • 21
  • 33
0

Use UIWebView and set it's dataDetectorTypes property or use a button and on click event try using below code,

-(IBAction)openLink:(UIButton *)sender
{
  NSString*myurl=sender.titleLabel.text;
  NSURL *url = [NSURL URLWithString:myurl];
  [[UIApplication sharedApplication] openURL:url];
}
Amar
  • 13,202
  • 7
  • 53
  • 71
rahul
  • 178
  • 5