开发者

UIButton not showing in UIScrollView

This is my code, been at it for awhile, but still can't get it to work.

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:UICont开发者_JAVA百科rolStateNormal];
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];


Oops solved, the button frame was larger than the scrollview.


BTW, you are allocating two buttons and only releasing one of them here. The first button allocated explicitly [with UIButton alloc] is never used and it's reference is clobbered by the subsequent assignment. A second button is allocated by [UIButton buttonWithType:] which is later released.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜