J'ai créé un UIButton sur une vue et sur l'action de l'UIButton [UIButton * button1_obj] un autre bouton [UIButton * button2_obj] est créé sur la même vue.UIButton n'étant pas cliqué dans la programmation de l'iPhone
Je suis confronté à ces 2 problèmes ... s'il vous plaît guidez-moi comment procéder.
button1_obj apparaît quand je lance mon projet, mais son pas cliqué ou mis en évidence, ni aucune exception est levée. Sur l'action de button1_obj, button2-obj doit apparaître sur la même vue, comment effacer la vue avant d'y placer button2_obj.
code pour la 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];
}
j'ai déclarer UIButton_G_obj, buttonUIObj, subMainView_G_obj GLOBALEMENT.
hey merci pour la solution (2) .. cela a fonctionné !! pour (1), j'ai mis à jour la question ci-dessus. – suse
J'ai un problème dans la solution (2). Si je donne le code comme [Button1_obj removeFromSuperview] alors il enlève seulement un bouton. Je veux que toute la vue soit éclaircie et donne une nouvelle vue. Comment devrais-je faire ça ?? – suse