我有一个数据数组。而且wr我的数据没有显示在屏幕上。不知道,我缺少什么。
@property NSMutableArray *NotifTotal;
@interface HomeVC ()<UITableViewDelegate, UITableViewDataSource>
@end
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.NotifTotal count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"FilterTableViewCell";
FilterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *dict;
dict = [self.NotifTotal objectAtIndex:indexPath.row];
NSLog(@"%@", dict); // data is coming.
NSString* salt = [dict objectForKey:@"salt"];
NSString* name = [dict objectForKey:@"Name"];
NSLog(@"%@%@", name,swerk); // in console i can print the data
cell.sLabel.text = [NSString stringWithFormat: @"%@", salt];
cell.nLabel.text = [NSString stringWithFormat: @"%@", name];
return cell;
}
为什么我的数据没有显示在屏幕上。我在屏幕上也添加了代表和数据源。任何解决方案?
最佳答案
您说过“我在屏幕上也添加了代理人,数据源”,但对我来说还不是很清楚,这意味着您要使HomeVC
符合UITableViewDelegate
和UITableViewDataSource
作为已发布的代码,或者您实际上是设置了代理人您的UITableView的HomeVC
。因此,您应该检查以下内容:
使用Interface Builder或以下代码将UITableView的数据源设置为HomeVC
:
self.tableView.dataSource = self; // I am assuming self == HomeVC instance
确保
[self.NotifTotal count] > 0
。通过在
cellForRowAtIndexPath
上添加一个断点并确认它已被调用,确保它与UITableView的配置问题无关。如果不是,请返回上面的2点。
如果是:这是UI问题,让我们检查单元格的高度是否接近0或它们是否具有透明颜色等等。您可以使用Xcode的View Debugging工具来调试问题。
关于ios - 客观c-uitableview无法在屏幕上显示数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54724758/