我正在使用分组 TableView 使用数据库开发联系人列表。当列表中没有联系人时,我必须在 tableview 上显示消息“No Contacts”。我该怎么做?
分享你的想法..
提前致谢
最佳答案
假设您正在使用数组来存储所有联系人,然后使用以下委托(delegate)
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// You can also modify this condition according to a specific section
if([YOUR_ARRAY count] == 0)
{
return 1;
}
else
return [YOUR_ARRAY count];
}
现在在下面的委托(delegate)中向表中添加数据
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Initialise your cell
if([YOUR_ARRAY count] > 0){
// add your array data to cells
}
if([YOUR_ARRAY count] == 0){
// this means no contacts in array and therfore you have only one cell to display NO CONTACTS
}
return cell;
}
关于iphone - UITableviewCell 在表中没有数据时显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11101069/