我已經在視圖上創建了一個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