代码之家  ›  专栏  ›  技术社区  ›  Benjamin Ortuzar

在自定义uiview的背景上查看tableviewlines

  •  3
  • Benjamin Ortuzar  · 技术社区  · 16 年前

    我有一个viewcontroller,它有一个TableView和一个自定义加载uiview,在加载TableView的数据时显示一个加载消息和微调器。 自定义uiview有一个我可以看到的红色背景,但我仍然可以看到TableView的线条,我如何才能在不看到背景上的TableView线条的情况下显示自定义uiview。

    @implementation LoadingView
    
    @synthesize spinner;
    
    - (id)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            // Initialization code
            [self setUserInteractionEnabled:NO];
            [self setBackgroundColor:[UIColor blueColor]];
    
            // Spinner
            spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            [spinner setCenter:CGPointMake(320/2, 150)];
            [self addSubview:spinner];
            [spinner startAnimating];
    
            //title label
            UILabel *titleLabel = [[UILabel alloc] init];
            titleLabel.text = @"Loading...";
            titleLabel.font = [UIFont boldSystemFontOfSize:18];
            titleLabel.lineBreakMode =  UILineBreakModeWordWrap;
            titleLabel.backgroundColor = [UIColor clearColor];
            titleLabel.textColor = [UIColor blackColor];
            titleLabel.textAlignment = UITextAlignmentLeft;
            CGFloat height = [titleLabel.text sizeWithFont: titleLabel.font constrainedToSize: CGSizeMake(300, 1500) lineBreakMode: UILineBreakModeWordWrap].height;
            [titleLabel setFrame: CGRectMake(120, 180, 100, height)];
            [self addSubview:titleLabel];
            [titleLabel release];
    
        }
        return self;
    }
    
    
    - (void)drawRect:(CGRect)rect {
    
    }
    
    
    - (void)dealloc {
        [super dealloc];
        [spinner release];
    }
    
    
    @end
    
    2 回复  |  直到 16 年前
        1
  •  0
  •   vfn    16 年前

    您可以将行设置为“关闭”,当您开始加载过程时,将它们设置为透明的。

    
    // Setting transparent
    tableView.separatorColor = [UIColor clearColor];
    

    当您删除加载的uiview时,您可以更改所需的uiview的颜色。

    
    // Setting the desired color
    tableView.separatorColor = [UIColor grayColor];
    

    另一种选择是在没有要显示的数据时将表视图设置为隐藏,而在第一行或多行出现时,将表视图设置为不隐藏。

    希望这对你有帮助!

    干杯,
    变频调速

        2
  •  -1
  •   Benjamin Ortuzar    16 年前

    问题是ViewController中的self.view直接分配了TableView。解决方案是分配self.view一个uiview,并在self.view的顶部添加tableview和自定义uiview。

    这是来自ViewController的示例代码。

    - (void)loadView {
    
    
        UIView *aView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    
        //tableView
        self.tableView = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain] autorelease];
        //set the rowHeight once for performance reasons.
        //self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.rowHeight = 75;
        self.tableView.backgroundColor = [UIColor clearColor];
        self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);                    
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.autoresizesSubviews = YES;
    
        [aView addSubview:tableView];
    
        //set the rowHeight once for performance reasons.
        self.view = aView;
        [aView release];
    
    }
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        loadingView = [[LoadingView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [self.view addSubview:loadingView];
    
    
        //fetch productsArray
        [self productListRequestStart];
    
    }
    
    推荐文章