delegate_ = delegate;
}
+- (void) setHook:(id)hook {
+ hook_ = hook;
+}
+
- (void) setPage:(RVPage *)page {
if ([pages_ count] != 0)
[[pages_ lastObject] setPageActive:NO];
[navbar_ enableAnimation];
}
-- (void) pushPage:(RVPage *)page {
- if ([pages_ count] != 0)
- [[pages_ lastObject] setPageActive:NO];
+- (void) swapPage:(RVPage *)page {
+ if ([pages_ count] == 0)
+ return [self pushPage:page];
+
+ [[pages_ lastObject] setPageActive:NO];
+
+ [navbar_ disableAnimation];
+ resetting_ = true;
+ [navbar_ popNavigationItem];
+ resetting_ = false;
+
+ [self pushPage:page animated:NO];
+ [navbar_ enableAnimation];
+}
+- (void) pushPage:(RVPage *)page animated:(BOOL)animated {
NSString *title = [self getTitleForPage:page];
NSString *backButtonTitle = [page backButtonTitle];
[navitem setBackButtonTitle:backButtonTitle];
[navbar_ pushNavigationItem:navitem];
- BOOL animated = [pages_ count] == 0 ? NO : YES;
[page setFrame:[transition_ bounds]];
[transition_ transition:(animated ? 1 : 0) toView:page];
[page setPageActive:YES];
[navbar_ setAccessoryView:[page accessoryView] animate:animated removeOnPop:NO];
}
+- (void) pushPage:(RVPage *)page {
+ if ([pages_ count] != 0)
+ [[pages_ lastObject] setPageActive:NO];
+ [self pushPage:page animated:([pages_ count] == 0 ? NO : YES)];
+}
+
- (void) pushBook:(RVBook *)book {
[delegate_ popUpBook:book];
}
[navitem setTitle:title];
}
-- (NSString *) _leftButtonTitleForPage:(RVPage *)page {
- return [page leftButtonTitle];
+- (void) _leftButtonTitle:(NSString *&)leftButtonTitle style:(UINavigationButtonStyle &)leftButtonStyle forPage:(RVPage *)page {
+ leftButtonTitle = [page leftButtonTitle];
+ leftButtonStyle = [page leftButtonStyle];
}
- (void) reloadButtonsForPage:(RVPage *)page {
if ([pages_ count] == 0 || page != [pages_ lastObject])
return;
- NSString *leftButtonTitle([self _leftButtonTitleForPage:page]);
- UINavigationButtonStyle leftButtonStyle = [page leftButtonStyle];
+
+ NSString *leftButtonTitle;
+ UINavigationButtonStyle leftButtonStyle;
+ [self _leftButtonTitle:leftButtonTitle style:leftButtonStyle forPage:page];
+
UINavigationButtonStyle rightButtonStyle = [page rightButtonStyle];
//[navbar_ showButtonsWithLeftTitle:leftButtonTitle rightTitle:[page rightButtonTitle] leftBack:(leftButtonTitle == nil)];
}
- (void) reloadData {
- for (int i(0), e([pages_ count]); i != e; ++i) {
- RVPage *page([pages_ objectAtIndex:(e - i - 1)]);
+ size_t count([pages_ count]);
+ for (size_t i(0); i != count; ++i) {
+ RVPage *page([pages_ objectAtIndex:(count - i - 1)]);
[page reloadData];
}
+
+ if (count != 0) {
+ RVPage *page([pages_ lastObject]);
+ [self reloadButtonsForPage:page];
+ }
}
- (CGRect) pageBounds {
}
- (void) close {
+ if (hook_ != nil)
+ [hook_ didCloseBook:self];
}
@end
@implementation RVPopUpBook
-- (NSString *) _leftButtonTitleForPage:(RVPage *)page {
- NSString *title([super _leftButtonTitleForPage:page]);
- return (cancel_ = title == nil && [pages_ count] == 1) ? @"Cancel" : title;
+- (void) _leftButtonTitle:(NSString *&)leftButtonTitle style:(UINavigationButtonStyle &)leftButtonStyle forPage:(RVPage *)page {
+ [super _leftButtonTitle:leftButtonTitle style:leftButtonStyle forPage:page];
+ if ((cancel_ = leftButtonTitle == nil && [pages_ count] == 1)) {
+ leftButtonTitle = @"Cancel";
+ leftButtonStyle = UINavigationButtonStyleNormal;
+ }
}
- (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
- (void) close {
[self popFromSuperviewAnimated:YES];
+ [super close];
}
@end