iOS筆記:查詢結果爲空,顯示無數據的方法(UITableView Display No Data)

iOS查詢返回空結果集,界面上提示空數據的方法(No Data)code

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.articles.count) {
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.tableView.backgroundView = nil;
        return 1;
    } else {
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        UILabel *label = [[UILabel alloc] initWithFrame:self.tableView.bounds];
        label.text = @"沒有搜索到相關文章\n請輸入其它關鍵字再次搜索";
        label.numberOfLines = 2;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor lightGrayColor];

        self.tableView.backgroundView = label;
    }

    return 0;
}
相關文章
相關標籤/搜索