Let me describe the situation I'm trying to do:
I have a list of items. When I go to ItemDetailView, which is a UITableView. I want to do paging here like: When I scroll down from the table view, I want to display the next element. Like in Good Reader:
Swap Examples http://img245.yfrog.com/img245/2073/pricethat.jpg
I am currently trying to use two approaches, but both of them do not work for me. 1st: I allow my UITableView to view the scroll, and I have good animation, and everything works fine, but sometimes the UITableView gets an event instead of my scroll. And since UITableView is already a UITableView, this approach seems like a bad idea. Here is the code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height * kNumberOfPages);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
[self loadScrollViewWithPage:0];
}
- (void)loadScrollViewWithPage:(int)page {
if (page < 0) return;
if (page >= kNumberOfPages) return;
[self.currentViewController.view removeFromSuperview];
self.currentViewController = [[[MyNewTableView alloc]initWithPageNumber:page] autorelease];
if (nil == currentViewController.view.superview) {
CGRect frame = scrollView.frame;
[scrollView addSubview:currentViewController.view];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (pageControlUsed) {
return;
}
CGFloat pageHeight = scrollView.frame.size.height;
int page = floor((scrollView.contentOffset.y - pageHeight / 2) / pageHeight) + 1;
[self loadScrollViewWithPage:page];
}
- (IBAction)changePage:(id)sender {
int page = pageControl.currentPage;
[self loadScrollViewWithPage:page];
CGRect frame = scrollView.frame;
[scrollView scrollRectToVisible:frame animated:YES];
pageControlUsed = YES;
}
: pop push of navigationController, ItemDetail . , .
, , ,