我已经在视图上创建了一个UIButton,并在UIButton的[UIButton * button1_obj]上创建了一个按钮[UIButton * button2_obj]在同一视图上创建。在iPhone编程中未点击UIButton
我正面临着这两个问题...请指导我如何继续。
button1_obj在我运行我的项目时出现,但没有被点击或突出显示,也没有任何异常被抛出。
在button1_obj的动作上,button2-obj必须出现在同一个视图上,在放置button2_obj之前如何清除视图。
规范的问题(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];
}
我宣布UIButton_G_obj,buttonUIObj,subMainView_G_obj GLOBALLY。
嘿感谢解决方案(2)..它的工作! (1)的 ,我已更新上述问题。 – suse 2010-03-24 03:43:38
我在解决方案(2)中遇到问题。如果我将代码作为[Button1_obj removeFromSuperview],那么它只会删除一个按钮。我希望整个观点得到澄清并提出新的看法。我应该怎么做? – suse 2010-03-24 04:18:09