2014-01-20 5 views
1

알림보기에서 스 와이프중인 셀의 행 번호를 표시하고 싶습니다. 내가 가지고있는 문제는 나는 스 와이프되는 행 번호를 가져올 수 없다는 것인데, 항상 "0"을 보여줍니다.셀이 왼쪽으로 스 와이프 될 때 Alertview에 rownumber를 표시합니다. 인터페이스 빌더에 스 와이프 제스처가 추가되었습니다.

인터페이스 작성 도구로 스 와이프 제스처를 추가했습니다.

내 .H 파일

@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *gestureSwipeLeft; 
@property (nonatomic, retain) NSIndexPath * indexPath; 
@property (nonatomic, assign) int test; 

내하는 .m 파일

cellForRowAtIndexPath가 호출 될 때마다 덮어 쓰는 _test 위 내 댓글에 언급, 당신 gestureRecognizer 콜백 내에서 이런 식으로 뭔가를 시도으로
- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{ 

UIAlertView *getRow = [[UIAlertView alloc]initWithTitle:@"RowNumberSwiped" message:[NSString stringWithFormat:@"%i", _test] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

[getRow show]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
_test = self.indexPath.row; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myBasicCell"]; 

thingToDoDoc *things = [self.things objectAtIndex:indexPath.row]; 

UILabel *lblTitle = (UILabel *)[cell viewWithTag:100]; 
lblTitle.text = things.data.title; 

UIImageView *ratingImageView = (UIImageView *)[cell viewWithTag:101]; 
// _lblTitle.text = things.data.title; 
if (things.data.isDone == 2) { 
    ratingImageView.image = [UIImage imageNamed:@"checkmark.png"]; 
} 

return cell; 
} 
+0

'cellForRowAtIndexPath'는 tableView에서 한 행당 한 번 호출되며 행이 표시 될 때마다 '_test' 덮어 쓰기가됩니다. –

+0

맞습니다. 잊었 어! 내 문제에 대한 해결책이 있습니까? – Dridia

+0

답변을 추가했습니다. 문제를 해결할 경우 답을 upvote/up으로 표시하는 것을 잊지 마십시오. 의견을 남기지 않으면 –

답변

0

-(void)cellSwipe:(UISwipeGestureRecognizer *)gesture 
{ 
    CGPoint location = [gesture locationInView:tableView]; 
    NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location]; 
    UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath]; 

    //Your own code... 
} 
+0

내 gesturRecognizer 콜백을 사용 하시겠습니까? 새 코드를 어디에 넣어야합니까? – Dridia

+0

@ user3100927 gestureRecognizer 콜백은 스 와이프가 감지되었을 때 실행하는 메소드입니다. 당신이 사용하는'handleSwipeLeft' 메소드는 거의 동일합니다. 그럼'handleSwipeLeft' 안에는 내 샘플에있는 두 변수의'indexPath'와'cell'을 가질 것입니다 –

+0

정말 고마워요 !! 그것은 완벽하게 작동합니다! – Dridia

3

tr에 대해 _test int 변수가 필요하지 않습니다. 달성하기 위해 잉. 그리고 tableView : cellForRowAtIndexPath의 현재 코드에 따라이 메소드가 호출 될 때마다 _test에 새 indexPath.row 값을 할당합니다 (_test가 매번 덮어 쓰입니다). 그리고 self.indexPath의 값을 언급 된 코드의 아무 곳에 나 설정하지 않습니다. Alertview에 다른 방식으로 표시하려면 현재 스 와이프 된 행의 인덱스를 가져와야합니다. 코드를보고 다음과 같이 코드를 바꿉니다 :

- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{ 

    UIAlertView *getRow = [[UIAlertView alloc]initWithTitle:@"RowNumberSwiped" message:[NSString stringWithFormat:@"%i", [yourTableView indexPathForRowAtPoint:[self.gestureSwipeLeft locationInView:yourTableView]].row] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [getRow show]; 
} 

희망이 있으면 도움이됩니다.

관련 문제