2013-04-22 6 views
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"); 
} 
+1

는, jQuery과 이미 터치 감지 위임이 - (무효)있는 tableView : (jQuery과 *)있는 tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath.이 메서드에서는 [[UIApplication sharedApplication] openURL : [NSURL URLWithString : url]];을 호출 할 수 있습니다. – Raj

답변

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]; 
} 

이 일을하려면, 나는 다음과 같은 기준에 포함 : 당신이 touchesBegan를 사용하는 이유는

- (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]]; 
} 
관련 문제