Hi,
I was trying to make an application where there is a table with names of some items and when you click on one item, a new view with the details will be shown, now I donot want the user to go back to the tableview again and select the next item to see its details. I want to implement a scrollView with paging so that the user can swipe through all the items without going back.
I have used some codes from "
Iphone Noob viewing images as photos.app" and was able to make it work. Now the problem is that even if I click the first item or the second item.... the detail view starts with the details of first item. I am not sure how to fix this issue.
Please find some relevant codes
When I click on an item I am loading the scroll view and passing the array with list of items and its details.
ScrollViewController.m
Code:
- (void)viewDidLoad {
self.title=@"List Of Items";
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < [self.detailsArray count]; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.detailsArray count], scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
[self loadPage:0];
[self loadPage:1];
}
- (void)loadPage:(int)page {
if (page < 0) return;
if (page >= [self.detailsArray count]) return;//detailsArray has the entire list of items
// replace the placeholder if necessary
DetailedViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
NSDictionary *itemAtIndex = (NSDictionary *)[self.detailsArray objectAtIndex:page];
controller = [[DetailedViewController alloc] initWithDictionary:itemAtIndex];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
if (nil == controller.view.superview) {
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
//[scrollView scrollRectToVisible:frame animated:NO];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
[self loadPage:page - 1];
[self loadPage:page];
[self loadPage:page + 1];
}
It will be helpful if I could get some tutorials or sample codes?
Thanks
-John