views:

335

answers:

1

hello,

i've the following code for button creation and on action of button , i'm calling buildUI method

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; [uiWorkAreaView_G_obj clearsContextBeforeDrawing]; CGRect cgRct2 = CGRectMake(0.0, 0.0, 480, 320); //define size and position of View uiWorkAreaView_G_obj = [[UIView alloc] initWithFrame:cgRct2]; //initilize the view 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. 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.

plz help.

A: 
[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. The return type of -buildUIWorkArea is irrelevant.

You probably want to send -buildUIWorkArea to self instead:

[UIButton_G_obj addTarget:self action:@selector(buildUIWorkArea)
         forControlEvents:UIControlEventTouchUpInside];
KennyTM
hey Kenny , thanks for replying.. after making addTarget:self, now i'm not gettin exception, but the action is not being performed. its entering into @selector(buildUIWorkArea),but not performing the action inside.
suse
could you figure out what the problem could be??
suse
And i could click the UI button only once in subMainView_G_obj, after tat i'm not able to click config button and neither UI button again.
suse
@suse: Have you actually clicked the button? If `-buildUIWorkArea` is called, then I consider your original question answered, and please start a new question for a new problem.
KennyTM
@Kenny: thanks a lots
suse