Ha ii ,i am doing a reader application which have chapters in it,i have done the swipe recognition property in tableview for reloading tableview with next and previous chapters right-swipe for next and left swipe for previous.And at the same time i added button for same function in button click,the problem is when the chapter ends that means the book containing only 9 chapters and if i reach the 9th chapter the swipe propert for right have to be stopped and vice versa.But i have done it in button by disabling the button if the chapter 9 loda it atomatically disabled the button so the user didnt tap the button,i want this same methode in my swipe right and left function>how to do this this is my code for swipe
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];
}
EDIT:::
-(void) handleSwipeGestureleft:(UISwipeGestureRecognizer*)recognizer {
delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
[delegate reloadVerses];
[self resetReadViewToVerse:1];
}
this is the method where i hides the button or disabled the button here i want to stop and start the gesture.Please help me.
Thanks in advance.
Thanks in advance.
edit
-(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;
}
You don’t need to deactivate the gesture you just need to check that the selectedChapter + 1 is not more than the total number of chapters, if it is you ignore the gesture.
EDIT:
You can do something like this (assuming you can ask the delegate totalNumberOfChapters):