0

对此的新功能,只是在触摸某个 UITableView 单元格时尝试加载链接。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
  NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
  NSArray *deals = [dic objectForKey:@"deals"];
  NSDictionary *dealOne = [deals objectAtIndex:0];
  NSString *url = [dealOne objectForKey:@"url"];

  UITouch *touch = [[event allTouches] anyObject];

  if([touch isKindOfClass:[UITableViewCell class]])
  {
    UITableViewCell *cell;
    CGPoint location = [touch locationInView: self.view];
    cell.center = location;

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  }
  NSLog(@"TABLECELL TOUCHED");
}
4

1 回答 1

0

使用以下方法解决。在这种情况下,我希望在为“finalDealOne”触摸单元格时加载链接。双击单元格时,将加载链接。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
{
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
  NSArray *deals = [dic objectForKey:@"deals"];
  NSDictionary *dealOne = [deals objectAtIndex:0];
  NSString *title = [dealOne objectForKey:@"title"];
  NSString *finalDealOne = [NSString stringWithFormat:@"Deal One:\n\n''%@''\n\nDouble tap here to redeem offer.",title];

  (NSIndexPath *)indexPath
  UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(finalDealOne)];
  tapped.numberOfTapsRequired = 2;

  [cell addGestureRecognizer:tapped];
}

为了完成这项工作,我提供了以下参考:

 - (void)finalDealOne
 { 
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
    NSArray *deals = [dic objectForKey:@"deals"];
    NSDictionary *dealOne = [deals objectAtIndex:0];
    NSString *url = [dealOne objectForKey:@"url"];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
 }
于 2013-04-23T01:42:35.807 回答