0
這個新的,只是試圖使一個鏈接加載,如果某個UITableView單元格被觸摸。如何在UITableViewCell觸摸上加載URL
-(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中已經有一個觸摸檢測委託是 - (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath。在這個方法中,你可以簡單地調用[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; – Raj 2013-04-23 10:27:01