[英]objective c - table view not able to show the data in the screen
我有一个数据数组。 而且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的配置问题无关。
这看起来像是xib问题。 我在中间添加了一些代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"FilterTableViewCell";
FilterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Add this part
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FilterTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//end
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.