Yaz*_*zmi 8 iphone objective-c uitableview
我的UITableView从互联网上获取数据.有时它不会收到任何(细胞)数据.它只显示一张空白表.
如何向用户显示未找到数据记录的消息/单元格?
Dan*_*Ray 25
您希望返回一个报告缺少数据的单元格.
如果你将你的单元格数据保存在一个类属性的数组中(比方说NSArray *listings),你可以去:
-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
if ([self.listings count] == 0) {
return 1; // a single cell to report no data
}
return [self.listings count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.listings count] == 0) {
UITableViewCell *cell = [[[UITableViewCell alloc] init] autorelease];
cell.textLabel.text = @"No records to display";
//whatever else to configure your one cell you're going to return
return cell;
}
// go on about your business, you have listings to display
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11570 次 |
| 最近记录: |