
Question:
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
Solution:1
â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
Solution:2
scrollView.contentSize = CGSizeMake(320, 1000);
against
scrollView.contentSize = CGSizeMake(1000, 320);
Solution:3
Are you sure this is fine?
scrollView.contentSize = CGSizeMake(1000, 320); [scrollView setAutoresizesSubviews:YES]; [scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
I usually would set the contentSize according the views I add.
Solution:4
I think you want to do sth. like [scrollView setDocumentView:yourContentViewToBeScrolled]; A ScrollView is just a View like all others. It extens from A to B, autosizes or not ⦠and did get the abilty to manage a document view: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Creating.html#//apple_ref/doc/uid/TP40003226-SW1
Greetings
Solution:5
Sorry, but you wrote âa view controller which contains just a scroll viewâ â" and I didnât have an eye on your tags. Is scrollEnabled set to (default value) YES? And: âThe scroll view itself does no drawing except for displaying vertical and horizontal scroll indicators. The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it âbouncesâ back when scrolling exceeds the bounds of the content. The object that manages the drawing of content displayed in a scroll view should â¦â (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html). â" Du you draw?
Maybe you should have an eye on the sample code mentioned there?
Greetings
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon