Я новичок в разработке iPhone. У меня есть представление таблицы с 6 разделами, каждая секция имеет одну строку, в разделе 4Th добавляется UILabel. Этот текст UILabel является URL (www.google.com). Я хочу открыть сафари, когда я нажимаю на этом лейбле, но я не успех для открытого сафариВеб-браузер Safari не открывается с URL-адресом
я FOLLO этого UILabel with a hyperlink inside a UITableViewCell should open safari webbrowser?
Но это не работает.
Мой код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [Prep defaultBGColor];
if(indexPath.section == 3)
{
self.lblWebsite = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 270, 35)];
self.lblWebsite.backgroundColor = [UIColor clearColor];
self.lblWebsite.text= @"www.gmail.com";
self.lblWebsite.font =[UIFont fontWithName:@"Arial-BoldMT" size:16];
self.lblWebsite.textAlignment = UITextAlignmentLeft;
self.lblWebsite.userInteractionEnabled = YES;
self.lblWebsite.textColor=[UIColor blackColor];
[cell.contentView addSubview:self.lblWebsite];
UITapGestureRecognizer *gestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openUrl:)];
gestureRec.numberOfTouchesRequired = 1;
gestureRec.numberOfTapsRequired = 1;
[self.lblWebsite addGestureRecognizer:gestureRec];
[gestureRec release];
}
}
return Cell;
}
Метод
- (void)openUrl:(id)sender
{
UIGestureRecognizer *rec = (UIGestureRecognizer *)sender;
id hitLabel = [self.view hitTest:[rec locationInView:self.view] withEvent:UIEventTypeTouches];
if ([hitLabel isKindOfClass:[UILabel class]]) {
NSLog(@"%@",((UILabel *)hitLabel).text);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
}
}
Вот что моя ошибка ??
использование http: // также ... –