2011-11-10 29 views
0

Ha ii,我正在做一個閱讀器應用程序,其中有章節,我已經完成了tableview中的滑動識別屬性,用於重新載入tableview,下一章和之前的章節向右滑動,然後向左滑動,同時我在按鈕點擊中添加了同樣功能的按鈕,問題是當章節結束時,意味着僅包含9章的書,如果我到達第9章,右邊的滑動屬性必須停止,反之亦然。但是我已經完成了通過禁用按鈕,如果第9章loda它自動禁用了按鈕,因此用戶沒有點擊該按鈕,我想在我的左右滑動功能中使用同樣的方法>如何做到這一點,這是我的代碼滑動我們如何限制iPhone SDK中的手勢屬性?

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)]; 
    swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; // or whatever 
    [table addGestureRecognizer:swipeGesture]; 
    [swipeGesture release]; 
    UISwipeGestureRecognizer *swipeGestureleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureleft:)]; 
    swipeGestureleft.direction = UISwipeGestureRecognizerDirectionLeft; // or whatever 
    [table addGestureRecognizer:swipeGestureleft]; 
    [swipeGestureleft release]; 
-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer { 

    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1]; 
    [delegate reloadVerses]; 
    [self resetReadViewToVerse:1]; 
} 

編輯::: - (空)handleSwipeGestureleft:(UISwipeGestureRecognizer *)識別{

delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1]; 
    [delegate reloadVerses]; 
    [self resetReadViewToVerse:1]; 
} 

這是我隱藏按鈕或在這裏禁用按鈕,我想停止和啓動gesture.Please幫助我的方法。 在此先感謝。 在此先感謝。 編輯

-(void)resetReadViewToVerse:(int)verseNo; 
{ 
    if(![delegate.selectedChapter isEqualToString:@"1"]) 
    { 
     previousButton.enabled = YES; 
     table.tableHeaderView =previousButton; 


    } 
    else 
    { 
     previousButton.enabled = NO; 
     table.tableHeaderView =nil; 

    } 

    if(![delegate.selectedChapter isEqualToString:[NSString stringWithFormat:@"%d",[DbHandler mNumberOfChaptersInBook:delegate.selectedBook]]]) 
    { 
     nextButton.enabled =YES; 
     table.tableFooterView =nextButton; 


    } 
    else 
    { 
     nextButton.enabled = NO; 
     table.tableFooterView =nil; 

    } 
    -(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer { 


    if(![delegate.selectedChapter isEqualToString:[NSString stringWithFormat:@"%d",[DbHandler mNumberOfChaptersInBook:delegate.selectedBook]]]) { 
     // if the currentChapter is the last then do nothing 
     delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1]; 
     [delegate reloadVerses]; 
     [self resetReadViewToVerse:1]; 
    } 
    return; 



} 
-(void) handleSwipeGestureleft:(UISwipeGestureRecognizer*)recognizer { 

    if(![delegate.selectedChapter isEqualToString:@"1"]) 
    { 
     delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1]; 
     [delegate reloadVerses]; 
     [self resetReadViewToVerse:1]; 
    } 
    return; 


} 

回答

1

你並不需要停用你只需要檢查selectedChapter + 1不大於章節總數,如果你忽略了手勢姿態。

編輯:

你可以做這樣的事情(假設你可以要求委託totalNumberOfChapters):你樣的反應再次

-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer { 

    // delegate.selectedChapter should be NSInteger, would be easier 

    NSInteger currentChapter = [delegate.selectedChapter integerValue]; 

    if (currentChapter >= delegate.totalNumberOfChapters) { 
     // if the currentChapter is the last then do nothing 
     return; 
    } 

    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1]; 
    [delegate reloadVerses]; 
    [self resetReadViewToVerse:1]; 
} 
+0

感謝,但在哪裏我把情況請參閱我的編輯在我的問題。這是我把條件啓用和禁用下一章和prv章按鈕。 – ICoder

+0

先生我的時間結束了,tmaro mrng我將chk代碼謝謝非常多 – ICoder