So, i have a view controller which contains just a scroll view. In viewDidLoad, i add a view to it from a nib, but when i do that, the scrolling stops working. The view i added works though, i.e. i can click buttons, but half of it is off screen.
@implementation JCEKScrollViewController_iPhone
@synthesize scrollView;
- (void)viewDidLoad {
scrollView.backgroundColor = [UIColor redColor];
scrollView.delegate = self;
NSArray *nibParts = [[NSBundle mainBundle] loadNibNamed:@"JCEKKeyboard"
owner:self
options:nil];
//first object is the view
UIView *keyboard = [nibParts objectAtIndex:0];
scrollView.contentSize = CGSizeMake(1000, 320);
[scrollView setAutoresizesSubviews:YES];
[scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[keyboard setAutoresizesSubviews:YES];
[keyboard setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[scrollView addSubview:keyboard];
}
Thanks
“This is for iPhone, no document views exist” – so you don’t have anything to display? Why to scroll an empty rectangle?
Apple says “After initializing the NSScrollView instance you must, at a minimum, set the document view using the method setDocumentView: …”. They use (Listing 1) [scrollView setDocumentView:theImageView]; and theImageView there is a NSImageView. There is nothing like a NSDocumentView.
Let me have one guess: you don’t use the “real” MVC-pattern. What you are doing is having a VC-Object and a Model or just one single object for everything. Right? If so: you miss to find out the “pure art”.
No, you must not split this three parts all the time. It’s ok to combine two or even all three parts of the MVC-pattern. But before that you should do these small steps! Find out, how this should work. Here you will learn …
• a model ist just fot to have all the data for one job together. It’s a little (but not at all) like some document file (and that’s not .doc), just without file.
• the view is just one(!) way (maybe the only you have, but there can be as much as you want or need) to display some or all of the data, you want to show
• the controller manages them: it fetches data from the model(s) and puts them back; it holds the view(s) and tells them, what to do – and maybe gets data from them (some to be pushed to a model or some for other needs – this is a logical or, a “||” and not the xor, people use in natural speech!)
Sorry for my bad english. I wrote that just to make you curious. Just do an “RTFM”, or, in this circumstands, read the related parts of the developer documentation. For example http://developer.apple.com/iphone/library/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html could be a place to start with!
Greetings