1

I have a relatively simple app. I have a fullscreen UIView subclass (musicGridView) that the user interacts with, and a UIScrollView subclass (scrollView) that loads this class in, as well as a ViewController and mainWindow.xib.

Right now, I have a viewController instance loaded in the nib, which is of type myViewController. The nib also has instance of myUIView, which the myViewController is pointed to.

In AppDelegate, I do this:

[window addSubview:scrollView];
[scrollView addSubview: viewController.view];
scrollView.musicGridView = (MusicGridView*) viewController.view;

which I think is wrong. Ideally, the appDelegate doesn't have an instance of scrollView.

In scrollView's AwakeFromNib class, I do the initialization on the scrollView.

The way I think it should go, is load the [window addSubview:viewController.view] in appDelegate, and then point the viewController to an instance of scrollView instead of musicGridView. Then, in scrollView awakeFromNib add a subview of musicGridView.

Eventually, I want to create another view owned by scrollView that is actually a side TabBar (which isn't possible with the given API's) that the user can scroll to the left to reach.

So I guess amongst other MVC stuff, the question is, should the viewController point to the scrollView, which contains all other content UIView subclasses, including musicGridView?

4

2 回答 2

0

我是一个不使用 Interface Builder 进行 UI 设计的人;根据我的经验,您需要选择全 IB 或全程序化。为了解决您的特定问题,我认为您需要将 musicGridView 作为 UIScrollView 的实例或扩展。

这可以在您的自定义 viewController 的 loadView 方法中完成 - 只需将其初始化为 UIScrollView(并向其添加内容),而不是普通的旧 UIView。

但是,如上所述,这种方法与以 IB 为中心的方法不兼容,正如UIViewController 类参考中所确认的那样

UIViewController 的所有子类都应该实现 loadView 方法来设置视图属性,除非您从 nib 文件加载视图

于 2009-06-15T00:59:36.243 回答
0

听起来您没有使用 Interface Builder 来设计您的 UI。由于这是一个新项目,我建议这样做。您根本不必编写任何这样的代码。但是,您需要描述您的出路和行动。

与 IB 打交道时,您需要知道的最重要的两件事是IBOutletIBAction关键字。

示例类头:

@interface MyClass : NSObject {
  IBOutlet UIScrollView* myScrollView;
}

- (IBAction) doWork;

@end

现在,您可以使用 Interface Builder 将这两个东西连接起来,用鼠标将源拖到目的地。如果您需要更好地描述如何做到这一点,YouTube 上有很多关于 IB 的教程视频。

于 2009-06-12T22:57:24.293 回答