просмотр tableViewLines на фоне пользовательского UIView - PullRequest
3 голосов
/ 23 января 2010

У меня есть viewController, у которого есть tableView и пользовательский загрузочный UIView, который отображает сообщение о загрузке и спиннер во время загрузки данных tableView. У пользовательского UIView есть красный фон, который я могу видеть, но я все еще могу видеть строки tableView. Как я могу отобразить пользовательский интерфейс, не видя линий tableView на фоне.

@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 ]

0 голосов
/ 24 января 2010

Проблема заключалась в том, что self.view в viewController имел непосредственное назначение tableView. Решение состоит в том, чтобы назначить self.view UIView и добавить tableView и пользовательский UIView поверх self.view.

Это пример кода из 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];

}
0 голосов
/ 23 января 2010

Вы можете отключить строки при запуске процесса загрузки, установив их прозрачными.


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

А когда вы удаляете загрузочный UIView, вы меняете цвет на тот, который вам нужен.


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

Еще одна альтернатива - установить табличное представление скрытым, когда у вас нет данных для отображения, и, когда появляется первая или более строка, вы устанавливаете табличное представление как не скрытое.

Надеюсь, это вам поможет!

Приветствия,
VFN

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...