views:

127

answers:

4

Hi

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

A: 

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.

nacho4d
I changed it to `scrollView.contentSize = CGSizeMake([keyboard bounds].size.width, [keyboard bounds].size.height);` but it didnt change anything. Any other ideas?
joec
A: 

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

Objective Interested Person
This is for iPhone, no document views exist... sorry... any other ideas?
joec
A: 

“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

Objective Interested Person
Of course i have things to display! On the iPhone the setDocumentView method is not defined, as this is a UIScrollView not an NSScrollView.
joec
A: 

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

Objective Interested Person