2010-09-24 58 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:]分配。