在子视图中按下按钮时,应用崩溃 [英] App crash when pressing a button in a subview
问题描述
我对scrollView
有很大的疑问.我有这段代码,当我按下"registerView"的xib
文件中的按钮时,应用程序崩溃了:
I've a big problem with a scrollView
. I have this code and when i press a button that is in the xib
file of "registerView" then the app crashes:
MainViewController.m:
MainViewController.m:
ViewDidLoad:
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"中的按钮时,应用程序崩溃,并显示以下日志:
"RegisterView" is added to a scrollView
, but then when I push a button in "registerView" the app crashes with this log:
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:
Button: RegisterViewController.h:
- (IBAction)btn_reset:(id)sender;
RegisterViewController.m:
RegisterViewController.m:
- (IBAction)btn_reset:(id)sender {
}
并且我尝试在scrollView
中放置一个按钮,但是后来我无法访问文本字段"信息,因此我需要在"RegisterView"中放置一个按钮.
And I've tried to put a button in the scrollView
instead but then i cant access to "textfields" info, so I need to put a button in the "RegisterView".
推荐答案
在@interface中声明RegisterViewController * registerView或为其创建一个@property.
Declare the RegisterViewController *registerView in @interface or create a @property for it.
@interface XXXXX ()
{
RegisterView *registerView;
}
OR
@属性(非原子的,坚固的)RegisterView * registerView;
@property (nonatomic, strong) RegisterView *registerView;
这篇关于在子视图中按下按钮时,应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!