簡體   English   中英

空的uitableview部分的占位符

[英]placeholder for empty uitableview section

經過大量的搜索,我似乎無法找到我正在尋找的東西。

我有一個UITableview,其中一些部分可能是空白的。 這是一張圖片,幫助我了解我在說什么。 我想在頁腳和標題之間的中間有一些TEXT (不是表格單元格)。 有什么我可能忽略的嗎?

空節

我做的是創建一個與tableview相同大小的UILabel並將其添加到tableview,如:

UILabel* emptyLabel = [[UILabel alloc] init];
emptyLabel.textAlignment = UITextAlignmentCenter;
emptyLabel.backgroundColor = [UIColor clearColor];
emptyLabel.frame = self.tableView.bounds;
emptyLabel.text = @"Empty";
[self.tableView addSubview:emptyLabel];

然后,您可以使用隱藏屬性來顯示或隱藏它,例如emptyLabel.hidden = TRUE;

由於UITableViews的性質,我不確定您是否可以用其他東西替換UITableCell視圖。 但是沒有理由你不能完全改變表格單元本身看起來像普通的UITextLabel而不是單元格! 你可以這樣做:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    /* Initial setup here... */

    if (thisCellHasNoDataYet) {
        // Prevent highlight on tap
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
        cell.backgroundColor = [UIColor clearColor];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.textLabel.text = @"TEXT YOU WANT THE 'CELL' TO DISPLAY";
        // etc...
    }
    else {
        // Otherwise we have data to display, set normal cell mode
        [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
        cell.backgroundColor = [UIColor whiteColor];
        // etc...
}

這里的好處是,一旦你的條件得到滿足,你只需要將布爾值(我使用thisCellHasNoDataYet )設置為TRUE並在你的表上調用reloadData

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM