2010-09-24 37 views
0

這是我的代碼,它已經停留了一段時間,但仍然無法讓它工作。UIButton沒有在UIScrollView中顯示

suggestionScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, 320, 44)]; 

UIButton *button = [[UIButton alloc] init]; 
button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
      action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Show View" forState:UIControlStateNormal]; 
button.frame = CGRectMake(0, 44.0, 160.0, 40.0); 
[suggestionScrollView addSubview:button]; 
[suggestionScrollView bringSubviewToFront:button]; 
[self.view addSubview:suggestionScrollView]; 
[self.view bringSubviewToFront:suggestionScrollView]; 
[button release]; 
+0

您應該始終用平臺和/或語言標記問題。 – 2010-09-24 13:35:02

+0

對不起,下次再來。 – 2010-09-24 14:05:13

回答

0

哎呀解決了,按鈕框大於scrollview。

+0

更好地關閉問題或標記它。 – Sarah 2011-02-11 05:48:26

0

順便說一句,你正在分配兩個按鈕,只在這裏釋放其中一個。顯式分配的第一個按鈕(使用UIButton alloc)永遠不會被使用,並且它的引用被隨後的賦值所破壞。第二個按鈕由稍後發佈的[UIButton buttonWithType:]分配。