views:

185

answers:

1

I have a feeling I've botched the design of my app from a high level. Right now, I have one Controller, the App Delegate, Two UIViews (one is a subclass of Scrollview) and one nib for the controller.

In IB, I have set the class of the file owner to MusicGridController and then set the class of the UIView to MusicGridView. Thus, the instances of those classes are instantiated by the nib, right? Then, I have a UIScrollView, that I want to be layered on top of the MusicGridView. In the app Delegate, I've done this:

@synthesize window;
@synthesize viewController;
@synthesize scrollView;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    
    //[application setStatusBarHidden:YES animated:NO];
    //[window addSubview:viewController.view];


    scrollView.contentSize = CGSizeMake(480, 480);
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.alwaysBounceVertical = NO;
    scrollView.alwaysBounceHorizontal = NO;
//  scrollView.maximumZoomScale = 4.0;
//  scrollView.minimumZoomScale = 0.75;
    scrollView.delegate = self;
//  [viewController.view addSubview:scrollView];
    [window addSubview:scrollView];
    [scrollView addSubview:viewController.view];

    [window makeKeyAndVisible];
}

So, I'm adding the scrollView subclass to the window, then the view of the Controller as a subview of scrollView.

I think I'm fundamentally messed up on the architecture. Almost all of the code that interacts with the user so far is in my MusicGridView, and the controller literally does nothing.

My problem I'm running into now is that I need to pass touch events from the UIScrollview to the MusicGridView instance, but I don't know how to pass it to the right instance.

Ideally, I think I should probably load MusicGridView in the init method of the UIScrollView subclass, and then maybe have the UIView be an instance of the UIScrollView subclass. Would that work?

+1  A: 

I don't know how to address your question as a whole. But I can tell you that with your current architecture, you are not following the MVC paradigm. The app delegate should get your application off the ground, but you shouldn't need to add code in your app delegate for the internal responsibilities of your classes.

The property scrollView shouldn't be needed (I don't believe)

The configuration of the scrollView should be handled by whatever view's controller (MusicGridView?) that it is contained in. What is containg that scrollView object?

If the scrollView is the root view in a UINavigationController, than perhaps your subclass of the UINavigiationController should setup your scrollview instance.

Update:

From:

Ideally, I think I should probably load MusicGridView in the init method of the UIScrollView subclass, and then maybe have the UIView be an instance of the UIScrollView subclass. Would that work?

I believe your idea here is correct. I mixed up what your scrollview/MusicGridView objects were to represent.

Frank V