Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-12-2009, 07:25 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default UIScrollView+PagingEnabled

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
JohnMabassa is offline   Reply With Quote
Old 05-12-2009, 11:01 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default

Bump!! ny inputs guys?
JohnMabassa is offline   Reply With Quote
Old 05-19-2009, 05:25 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default

figured it out with the help of skyLarEC (ipodtouchfans). I need to use setContentOffset method.

-John
JohnMabassa is offline   Reply With Quote
Reply

Bookmarks

Tags
loadpage, paging, scrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 314
6 members and 308 guests
givensur, guusleijsten, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0