0

问题是我无法隐藏条形段。我想删除,因为它在给定时间只有一个段。

如果我删除或隐藏 UISegmentedControl,则在第一个单元格和导航栏之间保留一个空格。

在此处输入图像描述

不知道是哪一种观点,我必须改变框架......

    $3 = 0x0abbdae0 <UIWindow: 0x9f936b0; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x9f9b420>>
   | <UILayoutContainerView: 0xab84630; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0xab96490>>
   |    | <UITransitionView: 0xab4fe90; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xab94600>>
   |    |    | <UIViewControllerWrapperView: 0x9fe23f0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x9fe3170>>
   |    |    |    | <UILayoutContainerView: 0x9fe2c90; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x9fb6b00>>
   |    |    |    |    | <UINavigationTransitionView: 0x9fb6870; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x9fe39b0>>
   |    |    |    |    |    | <UIViewControllerWrapperView: 0x9f0d530; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x9f336d0>>
   |    |    |    |    |    |    | <UITableView: 0xb301800; frame = (0 0; 320 416); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0xabbdc80>; layer = <CALayer: 0xabc06e0>; contentOffset: {0, -0}>
   |    |    |    |    |    |    |    | <UITableViewBackgroundView: 0xabc0e70; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0xabc0ed0>>
   |    |    |    |    |    |    |    |    | <UIImageView: 0xabc0f00; frame = (0 0; 320 416); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xabc0f60>>
   |    |    |    |    |    |    |    |    | <UIView: 0xabc0fb0; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0xabc1010>>
   |    |    |    |    |    |    |    | <UITableViewCell: 0x9f3d010; frame = (0 55; 320 46); text = '1'; autoresize = W; layer = <CALayer: 0x9ff9560>>

我的可见性设置:

[self.SegmentControl removeAllSegments];

    if([_invitados count] > 0){
        [self.SegmentControl insertSegmentWithTitle:@"SegmentA" atIndex:0 animated:YES];
    }

    [self.SegmentControl insertSegmentWithTitle:@"SegmentB" atIndex:([self.SegmentControl numberOfSegments]==0 ? 0:1) animated:YES];

    if([_followers count] > 0){
        [self.SegmentControl insertSegmentWithTitle:@"SegmentC" atIndex:[self.SegmentControl numberOfSegments] animated:YES];
    }

    [self.SegmentControl setEnabled:YES forSegmentAtIndex:0];

    if([self.SegmentControl numberOfSegments]<=1){
        [self.SegmentControl removeFromSuperview];
    }
4

1 回答 1

1

如果你使用自定义 UIView,我建议你使用两个函数:[self setNeedsLayout][self layoutSubviews]. 在layoutSubviews方法中,您应该设置子视图框架和大小,启用或禁用它们,隐藏等。并setNeedsLayout在 UI 中进行一些更改后调用。

来自Apple 文档layoutSubviews如果您需要对子视图的布局进行比约束或自动调整大小行为提供的更精确的控制,请实施。

于 2013-07-10T06:18:25.993 回答