Ant*_*ton 3 objective-c uitableview uisegmentedcontrol ios
我使用以下代码在UITableView中添加UISegmentedControl.除了UISegmentedControl根本没有响应用户交互之外,一切正常.可能是什么事?
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section == 2) {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 44)]; // x,y,width,height
NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", nil];
UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:itemArray];
[control setFrame:CGRectMake(60.0, 0, 200.0, 40.0)];
[control setSegmentedControlStyle:UISegmentedControlStylePlain];
[control setSelectedSegmentIndex:0];
[control setEnabled:YES];
[headerView addSubview:control];
return headerView;
}
}
Run Code Online (Sandbox Code Playgroud)
您还应该有一个相应的heightForHeaderInSection方法,如下所示:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 2) return 44.f;
return 0.f;
}
Run Code Online (Sandbox Code Playgroud)
如果不是,则控件可能仍然出现,但不会在任何可触摸区域内绘制.
| 归档时间: |
|
| 查看次数: |
4621 次 |
| 最近记录: |