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.
精彩评论