2014-05-24 3 views
-1

버튼이있는 셀이 여러 개 있습니다. SimpleTableCell.hSimpleTableCell.m에 대해 nav 버튼을 다시 그려 넣은 버튼이있는 SimpleTableCell.xib에서 생성됩니다. 이 세포들은 다음과 같이 ImagesTableViewController.mImagesTableViewController.h에서 호출됩니다 naviguate테이블의 셀 식별

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

NSString *stringy = @"http://www.example.co.uk/"; 
    NSString *link = [stringy stringByAppendingString: images[indexPath.row]]; 
    NSString* encodedString = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

SDImageCache *imageCache = [SDImageCache sharedImageCache]; 
    [imageCache queryDiskCacheForKey:encodedString done:^(UIImage *image, SDImageCacheType cacheType) { 

     if (image){ 
      cell.thumbnailImageView.image = image; 
     }else{ 
      [cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:encodedString] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { 
       [imageCache storeImage:image forKey:encodedString]; 

      }]; 

     } 


    }]; 

[cell.nav addTarget:self action:@selector(naviguate) forControlEvents:UIControlEventTouchUpInside]; 

} 

입니다 : 내가 셀 버튼을 클릭 할 때 indexPath.row를 연결 걸려

-(void)naviguate{ 
    [UIView animateWithDuration:0.5 
          delay:0 
         options: UIViewAnimationOptionCurveEaseOut 
        animations:^{ 

         [_tableView setFrame:CGRectMake(0, 569, _tableView.frame.size.width, _tableView.frame.size.height)]; 
        } 
        completion:^(BOOL finished){ 
         [self performSegueWithIdentifier:@"link" sender:self]; 
        }]; 

} 

. 그래서 어느 셀이 눌러 졌는지 알 수 있습니다.

어떻게하면됩니까? 당신이 addTargetselector 매개 변수를 기대하는 그에게 변경 기억

-(void)naviguate:(id)sender 

:

답변

1

당신은 이벤트를 트리거 UIButton 허용하도록 핸들러를 바꿀 수

[cell.nav addTarget:self 
      action:@selector(naviguate:) 
    forControlEvents:UIControlEventTouchUpInside]; 

그런 다음 서브 클래스 수를 당신의 UIButton 및 셀을 만들 때 설정 한 속성으로 인덱스 경로를 추가하십시오.

처리기에서 하위 클래스 UIButton이 보낸 사람으로 전달되고 인덱스 경로 속성 값에 액세스 할 수 있습니다.

+0

가 어떻게 서브 클래스 않는 태그 귀하의 버튼을 검색하고 사용자가 설정 한 속성으로 인덱스 경로를 추가 할 수 있습니다 셀이 생성 될 때. – maxisme

+0

내 대답을 편집 할 수 없으므로 여기에서해야합니다. UIButton을 하위 클래스로 만들고 인덱스 경로 속성을 추가하는 새 클래스를 만듭니다. SimpleTableCell.xib에서 UIButton을 선택하고 속성 검사기에서 클래스를 UIButton에서 새 클래스로 변경합니다. – Calvedos

0

단추에 tag 속성을 사용하여 행을 저장할 수 있습니다. cellForRowAtIndexPath에서 - 이벤트 핸들러에서 다음

[cell.nav addTarget:self action:@selector(naviguate:) forControlEvents:UIControlEventTouchUpInside]; 
cell.nav.tag=indexPath.row; 

당신은 전송 버튼을 받고 당신은 단순히

-(void)naviguate:(id)sender { 

    UIButton *theButton=(UIButton *)sender; 

    // You can now get the row by accessing theButton.tag 

    [UIView animateWithDuration:0.5 
         delay:0 
        options: UIViewAnimationOptionCurveEaseOut 
       animations:^{ 

        [_tableView setFrame:CGRectMake(0, 569, _tableView.frame.size.width, _tableView.frame.size.height)]; 
       } 
       completion:^(BOOL finished){ 
        [self performSegueWithIdentifier:@"link" sender:self]; 
       }]; 

}