我对scrollView有很大的疑问。我有以下代码,当我按下“registerView”的xib文件中的按钮时,应用程序崩溃:

MainViewController.m:

ViewDidLoad:

UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = NO;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.contentSize = CGSizeMake(768, 1900);
[self.view addSubview:scrollView];


RegisterViewController *registerView = [[RegisterViewController alloc] init];
[scrollView addSubview:registerView.view];

“RegisterView”被添加到scrollView,但是然后当我在“registerView”中按下按钮时,应用程序崩溃并显示以下日志:
    2014-05-12 11:18:04.599 RegisterForm[16505:60b] -[UIScrollView modalPresentationStyle]: unrecognized selector sent to instance 0x13f517200
2014-05-12 11:18:04.602 RegisterForm[16505:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIScrollView modalPresentationStyle]: unrecognized selector sent to instance 0x13f517200'
*** First throw call stack:
(0x18a83709c 0x196c8dd78 0x18a83bd14 0x18a839a7c 0x18a7594ac 0x18d800a68 0x1000e76b4 0x18d70c2c0 0x18d70c044 0x18d7137dc 0x18d710ab0 0x18d78488c 0x1000e674c 0x18d7815cc 0x18d780fb8 0x18d77a9a0 0x18d70d530 0x18d70c720 0x18d77a0b0 0x190119128 0x190118c54 0x18a7f6fc8 0x18a7f6f28 0x18a7f514c 0x18a735b38 0x18d7792d4 0x18d7740e8 0x1000e7cd0 0x197277aa0)
libc++abi.dylib: terminating with uncaught exception of type NSException

按键:
RegisterViewController.h:
- (IBAction)btn_reset:(id)sender;

RegisterViewController.m:
    - (IBAction)btn_reset:(id)sender {
}

而且我尝试在scrollView中放置一个按钮,但是后来我无法访问“文本字段”信息,因此我需要在“RegisterView”中放置一个按钮。

最佳答案

在@interface中声明RegisterViewController * registerView或为其创建一个@property。

@interface XXXXX ()
{
 RegisterView *registerView;
}

要么

@property(非原子的,强的)RegisterView * registerView;

10-08 07:29