views:

282

answers:

1

Hello,

I've created a UIButton on a view and on action of the UIButton[UIButton* button1_obj] one more button[UIButton* button2_obj] is created on same view.

i'm facing these 2 issues...please guide me how to proceed.

  1. button1_obj is appearing when i run my project, but its not being clicked or highlighted, nor any exception is thrown.

  2. On action of button1_obj , button2-obj has to appear on the same view, how to clear the view before placing button2_obj on it.

Code for question (1):

-(void)start

{

NSLog(@"--------------------------------------------------------------------");

NSLog(@"Entered CView start");

    //define size and position of view 
    subMainView_G_obj = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480, 320)]; //initilize the view 
    //subMainView_G_obj.autoresizesSubviews = YES;              //allow it to tweak size of elements in view 

    UIButton_G_obj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];    
    UIButton_G_obj.frame = CGRectMake(100,70, 150, 50);
    UIButton_G_obj.backgroundColor = [UIColor clearColor];
    //UIButton_G_obj.adjustsImageWhenHighlighted = YES;
    [UIButton_G_obj setTitle:@"UI" forState:UIControlStateNormal];
    [UIButton_G_obj addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    [subMainView_G_obj addSubview:UIButton_G_obj];

    UIButton_G_obj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];    
    UIButton_G_obj.frame = CGRectMake(100,150, 150, 50);
    UIButton_G_obj.backgroundColor = [UIColor clearColor];
    UIButton_G_obj.adjustsImageWhenHighlighted = YES;
    [UIButton_G_obj setTitle:@"Configuration" forState:UIControlStateNormal];
    [UIButton_G_obj addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    [subMainView_G_obj addSubview:UIButton_G_obj];

    NSLog(@"Leaving CView start");
    NSLog(@"--------------------------------------------------------------------");
}

- (void)action:(id) sender
{

    NSLog(@"Inside action method.. On click of First View");
    buttonUIObj = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];   
    buttonUIObj.frame = CGRectMake(100,160,100,50);
    [buttonUIObj setTitle:@"Next View" forState:UIControlStateNormal];
    buttonUIObj.backgroundColor = [UIColor clearColor];
    [subMainView_G_obj addSubview:buttonUIObj];

}

i've declare UIButton_G_obj,buttonUIObj,subMainView_G_obj GLOBALLY.

A: 

Hard to know what the problem with button1_obj is, without seeing code. However, for (2), you will probably want to remove button1_obj by calling [button1_obj removeFromSuperview].

Ben Gottlieb
hey thanks for the solution(2).. it worked!!for (1), i've updated the above question.
suse
I have a problem in the solution(2). If i give the code as [Button1_obj removeFromSuperview] then it only removes one button. I want the whole view to be cleared and give a new view. How should i do that??
suse