简体   繁体   English

在iPhone编程中由于未捕获的异常'NSInvalidArgumentException'终止了应用程序

[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', in iPhone programming

i've the following code for button creation and on action of button , i'm calling buildUI method 我有以下代码用于按钮创建以及按钮的操作,我正在调用buildUI方法

CGRect cgRct = CGRectMake(10 ,30 ,400, 320); //define size and position of view 
subMainView_G_obj = [[UIView alloc] initWithFrame:cgRct]; //initilize the view 
subMainView_G_obj.autoresizesSubviews = YES;  

//set view property ov controller to the newly created view
// create Button's for modules in array (UIButtonTypeRoundedRect)
UIButton_G_obj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
UIButton_G_obj.frame = CGRectMake(100,30,100,50);
[UIButton_G_obj setTitle:@"UI" forState:UIControlStateNormal];
UIButton_G_obj.backgroundColor = [UIColor clearColor];
[subMainView_G_obj  addSubview:UIButton_G_obj];
//[UIButton_G_obj setEnabled:TRUE];
[UIButton_G_obj addTarget:subMainView_G_obj action:@selector(buildUIWorkArea) forControlEvents:UIControlEventTouchUpInside];

 [mainView_G_obj addSubview:subMainView_G_obj];

} -(void)buildUIWorkArea { //UIView* uiWorkAreaView_G_obj; }-(void)buildUIWorkArea {// UIView * uiWorkAreaView_G_obj; [uiWorkAreaView_G_obj clearsContextBeforeDrawing]; [uiWorkAreaView_G_obj clearsContextBeforeDrawing]; CGRect cgRct2 = CGRectMake(0.0, 0.0, 480, 320); CGRect cgRct2 = CGRectMake(0.0,0.0,480,320); //define size and position of View uiWorkAreaView_G_obj = [[UIView alloc] initWithFrame:cgRct2]; //定义View的大小和位置uiWorkAreaView_G_obj = [[UIView alloc] initWithFrame:cgRct2]; //initilize the view uiWorkAreaView_G_obj.autoresizesSubviews = YES; //初始化视图uiWorkAreaView_G_obj.autoresizesSubviews = YES;

 (UIButtonTypeRoundedRect)buttonUIObj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
    buttonUIObj.frame = CGRectMake(100.30,100,50);
    [buttonUIObj setTitle:BUTTON  forState:UIControlStateNormal];
    buttonUIObj.backgroundColor = [UIColor clearColor];
    [uiWorkAreaView_G_obj  addSubview:buttonUIObj];
    [buttonUIObj addTarget:uiWorkAreaView_G_obj action:@selector(showModuleView:) forControlEvents:UIControlEventTouchUpInside];


 [mainView_G_obj clearsContextBeforeDrawing];
 [mainView_G_obj addSubview:uiWorkAreaView_G_obj];

} }

On click of button UI which is on UIView uiWorkAreaView_G_obj , it has to create one more button BUTTON on UIView uiWorkAreaView_G_obj.and after placing the button each of there subviews, i'm placing those subviews upon a common mainview_G_obj of type UIView. 在UIView uiWorkAreaView_G_obj上单击按钮UI时,它必须在UIView uiWorkAreaView_G_obj上再创建一个按钮BUTTON,然后在每个子视图中放置按钮后,将这些子视图放置在UIView类型的通用mainview_G_obj上。 But its throwing an exception ....... 但是它抛出一个异常.......

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView buildUIWorkArea]:unrecognized selector sent to instance 0x57ca80' 

i didn't understand why its taking buildUIWorkArea's return type as UIView , when i've declared its return type as void. 我不明白为什么我将buildUIWorkArea的返回类型声明为void时将其作为UIView。

plz help. 请帮助。

[UIButton_G_obj addTarget:subMainView_G_obj action:@selector(buildUIWorkArea)
         forControlEvents:UIControlEventTouchUpInside];

This line means that, when the user touch-up-inside the button, the following function will be called: 该行表示,当用户触摸按钮内部时,将调用以下功能:

[subMainView_G_obj buildUIWorkArea];

Since subMainView_G_obj is a plain UIView, there's no -buildUIWorkArea method and thus the error. 由于subMainView_G_obj是普通的UIView,因此没有-buildUIWorkArea方法,因此没有错误。 The return type of -buildUIWorkArea is irrelevant. -buildUIWorkArea的返回类型无关紧要。

You probably want to send -buildUIWorkArea to self instead: 您可能想将-buildUIWorkArea发送给self

[UIButton_G_obj addTarget:self action:@selector(buildUIWorkArea)
         forControlEvents:UIControlEventTouchUpInside];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone上的stringByTrimmingCharactersInSet错误“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序” - “Terminating app due to uncaught exception 'NSInvalidArgumentException'” error with stringByTrimmingCharactersInSet on iPhone 由于未捕获的异常'NSInvalidArgumentException而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序, - Terminating app due to uncaught exception 'NSInvalidArgumentException', (由于未捕获的异常'NSInvalidArgumentException而终止应用程序) - (Terminating app due to uncaught exception 'NSInvalidArgumentException) 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException' iOS应用程序异常-由于未捕获的异常'NSInvalidArgumentException'而终止应用程序 - iOS App Exception - Terminating app due to uncaught exception 'NSInvalidArgumentException' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber objectAtIndex:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber objectAtIndex:] 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString isDescendantOfView:]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isDescendantOfView:]: 终止应用程序未捕获的异常“NSInvalidArgumentException” - Terminating app uncaught exception 'NSInvalidArgumentException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM