Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 11, 2010, 03:06 PM   #1
printf
macrumors regular
 
Join Date: Aug 2008
Create UIScrollView Programmatically

i'm going off this programming guide on how to create a scrollview programmatically, but i can't get it to work as there's a few things i don't understand http://developer.apple.com/mac/libra.../Creating.html

right now, i have a window, a custom uiview and a viewcontroller. i try to alloc the uiscrollview inside the viewcontroller's loadView method but it crashes with an unrecognized selector exception.

the problem here is i don't really understand the relationship between the scrollview and the view controller. i know i'll add my custom uiview as a subview to the scrollview, but beyond that not much.
printf is offline   0 Reply With Quote
Old Jun 11, 2010, 05:05 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Let's see your code.
__________________
dejo is online now   0 Reply With Quote
Old Jun 11, 2010, 06:24 PM   #3
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
ok.

//app delegate's didFinishLaunchingWithOptions:
Code:
viewController = [[ViewController alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 480)];
	
[window addSubview:viewController.view];
[window makeKeyAndVisible];
//relevant methods from view controller
Code:
-(id)initWithFrame:(CGRect)rect {
	NSLog(@"initWithFrame");
	if (self = [super init]) {		
		scrollView = [[UIScrollView alloc] initWithFrame:rect];
	}
	return self;
}

- (void)loadView {
	NSLog(@"loadView");
	
	myView = [[CustomView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 480)];
	myView.autoresizesSubviews = YES;
	self.view = myView;        

	[scrollView setContentSize: CGSizeMake(320, 960)];	// twice as long as the screen
	[scrollView setFrame:CGRectMake(0, 0, 320, 480)];
	
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];	
	
	scrollView.contentSize = CGSizeMake(self.view.frame.size.width,myView.frame.size.height);
	[scrollView addSubview:myView];	
}
printf is offline   0 Reply With Quote
Old Jun 13, 2010, 02:53 AM   #4
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
ok, i got it working - finally.

basically it was a small oversight on my part. by changing this:

Code:
self.view = myView
to this:

Code:
self.view = scrollView;
it now works.
printf is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Draggable item in UISCrollview sregorcinimod iPhone and iPod touch Apps 1 Mar 30, 2011 01:38 AM
drag images in & out of UIScrollview BarryK88 iPhone/iPad Programming 3 Mar 23, 2011 05:49 AM
UIScrollView not showing the image! noahgolm iPhone/iPad Programming 12 Feb 17, 2011 11:49 PM
scroll a uitextfield and a uitextview in a uiscrollview franium iPhone/iPad Programming 14 Dec 4, 2010 02:51 AM
Create button programmatically SRossi Mac Programming 10 Jul 7, 2009 10:40 AM


All times are GMT -5. The time now is 10:48 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC