iphone - UITableviewCell 在表中没有数据时显示消息

标签 iphone ios uitableview

enter image description here

我正在使用分组 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/

相关文章:

c# - Monotouch 在使用设备构建时在 LINQ 查询上爆炸

ios - 如何在按下另一个键时模拟一个按键按下?

ios - 本地 HTML5 游戏无法在 UIWebKit 中加载

ios - 如何阐明其在位置模态中的使用目的?

uitableview - UIActionSheet 在 iPad 上因外部点击挂起界面而被解雇

iphone - 方便地将 HTML 转换为 NSString

iphone - 获取URL的动态内容?

iphone - iOS 将照片保存在应用特定的相册中

swift - TableView 中的 SDWebImage 向上滚动

ios - 使用 indexpath.row 引用从 JSON 对象数组中获取对象