【发布时间】:2013-04-22 06:22:42
【问题描述】:
这是新的,只是在触摸某个 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");
}
【问题讨论】:
-
为什么你使用 touchesBegan,UITableView 已经有一个触摸检测委托,它是 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath。在这个方法中你可以简单地调用[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
标签: arrays uitableview xcode4