我遇到一个非常烦人的问题:我正在创建一个UIScrollView,其中包含一个包含一些按钮的UIView。带按钮的UIView可以正常工作。但是,无论我如何操作,UIScrollView都会崩溃。它是否为空没有任何区别。它一直崩溃。

我很迷茫,不知道还能尝试什么。
非常感谢。

在viewController.h中

@interface tagstestViewController : UIViewController <UIScrollViewDelegate> {
        UIScrollView            *scrollViewContainer;
}

@property (nonatomic, retain) UIScrollView *scrollViewContainer;

在viewController.m中:
    UIScrollView *scv       =   [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, 320, 200)];
    scv.backgroundColor     =   [UIColor blackColor];
    scv.autoresizingMask    =   UIViewAutoresizingFlexibleHeight;
    scv.bounces             =   YES;
    scv.scrollEnabled       =   YES;
    scv.clipsToBounds       =   YES;
    scv.delegate            =   self;

    [self setScrollViewContainer:scv];

    [scv release];

    [self.view addSubview:scrollViewContainer];

最佳答案

将 View 添加到 View 层次结构后,是否立即释放viewController?因为这样做,我注意到即使应用程序运行正常,如果您使用“scv.delegate = self”,当尝试将委托(delegate)的消息传递到viewController时,它也会崩溃。

关于iphone - 触摸时UIScrollView使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3299526/

10-10 22:24