View a table of ViewLines in the background of a custom UIView

I have a viewController that has a tableView and a custom UIView loading that displays a boot message and a counter while the data of the View table is loading. The custom UIView has a red background that I can see, but I still see the rows of the View table. How can I display a custom uiview without seeing the table rows in the background.

@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
+3
source share
2 answers

The problem was that self.view in the viewController had the assigned tableView directly. The solution is to assign a self.view to a UIView and add a tableView and a custom UIView on top of self.view.

This is sample code from 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];

}
-1

"", , .


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

UIView, , .


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

, , , , .

, !

,
VFN

0

Source: https://habr.com/ru/post/1729690/


All Articles