【发布时间】:2012-12-28 11:37:08
【问题描述】:
我目前有一个 uitableview。
数据是从一个sqlite文件中获取的。
sqlite 文件的每一列将代表一个列表:标签、图像等
我用来获取行的代码是
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
AppDelegate* appdelegate = (AppDelegate*) [[UIApplication sharedApplication]delegate];
return [appdelegate.arrayDatabase count];
}
填充单元格的代码
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"simpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == Nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
AppDelegate * appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
ShowsList *sShows = [appdelegate.arrayDatabase objectAtIndex:indexPath.row];
cell.textLabel.text = [sShows strName ];
}
我遇到的问题:
我想使用标签列填充 ViewController1.tableview 的单元格文本,但它返回空行并在视图中显示空行/单元格。
但是我想通过计算空单元格并将计数应用于 numberOfRowsInSection: 方法或简单地隐藏空单元格来隐藏行。
Hide empty cells in UITableView & How to hide a section in UITableView? 看起来很相似,但没有解决我的问题。
有人可以指点我正确的路径或提供答案:)
非常感谢
托马斯
【问题讨论】:
-
你把tableView的delegate设置为self了吗??
-
appdelegate.arrayDatabase 中有什么?你得到什么了吗?
-
您的模型/数组中是否将空字符串作为@"" 或什么?
-
@sudha 如果我做 NSLog(@"%d",[appdelegate.arrayDatabase count]);是返回 30。相反,我只想计算数据库中的第 1 列。我认为这可以解决问题。有什么想法吗?
标签: ios uitableview