我有一个UIScrollView
,我创建了两个UIButtons
。第一个按钮按预期工作,但第二个按钮消失。它仍然存在并且可以接受点击,并且当您单击隐藏按钮时变为可见。
关于为什么出现第二个按钮的任何想法?
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
button_1 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
button_1.titleLabel.font = [UIFont systemFontOfSize:12];;
button_1.titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
button_1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button_1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button_1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button_1 setTitle:@"Circle" forState:UIControlStateNormal];
button_1.frame = CGRectMake(0.0, 30.00, 50, 20);
[button_1 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button_1];
button_2 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
button_2.titleLabel.font = [UIFont systemFontOfSize:12];;
button_2.titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
button_2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button_2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button_2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button_2 setTitle:@"Square" forState:UIControlStateNormal];
button_2.frame = CGRectMake(0.0, 120.0, 50, 20);
[button_2 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button_2];
答案 0 :(得分:2)
你想在这里实现的布局是什么?默认情况下,表格单元格(除非您有自定义rowHeights
) 44px高。你的button_2
将远离单元格边界,远远低于第一个按钮。此外,没有理由,实际上你不应该保留你正在创建的按钮。将它们添加到父视图时,它们将被保留。