nib(视图)上的 UITableview 不会重新加载 (Objective-C)
UITableview on nib (view) doesn't reload (Objective-C)
我想在 FAQViewcontroller 中重新加载一些数据。 tableview 放置在 nib 文件(视图) 中,该文件用 Viewcontroller 加载,这样调用:
FAQViewController *vc = [[FAQViewController alloc] initWithNibName:@"FAQViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
在 FAQViewcontroller 的 viewDidLoad 中,表格视图以正确的方式显示(我看到了分隔线,当我更改背景颜色时,它运行良好)。但是还没有要显示的信息,所以单元格是空的(如预期的那样)。
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerNib:[UINib nibWithNibName:@"FAQCell" bundle:nil] forCellReuseIdentifier:@"FAQCell"];
if (self.faqData == nil || [_faqData count] == 0) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[[DataModel sharedInstance] getFrequentlyAskedQuestions:^(NSError *error) {
}];
});
}
}
网络调用完成后,FAQViewcontroller中的这个函数被调用:
- (void)setFaqData:(NSArray *)faqData {
_faqData = faqData;
NSLog(@"%@", _faqData);
dispatch_async(dispatch_get_main_queue(), ^() {
[self.tableView reloadData];
});
}
但是 reloadData 什么也没做。 numberofrowsinsection 未被调用。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _faqData.count;
}
我不知道该怎么办。以前从来没有过这个(通常我在 Swift 中编码,也许我在 Objective-C 中忘记了什么)?
有谁知道我做错了什么?
非常感谢!
能否尝试将 tableView 作为强参考?
类似于:
@property (nonatomic, strong) IBOutlet UITableView *tableView
我想在 FAQViewcontroller 中重新加载一些数据。 tableview 放置在 nib 文件(视图) 中,该文件用 Viewcontroller 加载,这样调用:
FAQViewController *vc = [[FAQViewController alloc] initWithNibName:@"FAQViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
在 FAQViewcontroller 的 viewDidLoad 中,表格视图以正确的方式显示(我看到了分隔线,当我更改背景颜色时,它运行良好)。但是还没有要显示的信息,所以单元格是空的(如预期的那样)。
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerNib:[UINib nibWithNibName:@"FAQCell" bundle:nil] forCellReuseIdentifier:@"FAQCell"];
if (self.faqData == nil || [_faqData count] == 0) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[[DataModel sharedInstance] getFrequentlyAskedQuestions:^(NSError *error) {
}];
});
}
}
网络调用完成后,FAQViewcontroller中的这个函数被调用:
- (void)setFaqData:(NSArray *)faqData {
_faqData = faqData;
NSLog(@"%@", _faqData);
dispatch_async(dispatch_get_main_queue(), ^() {
[self.tableView reloadData];
});
}
但是 reloadData 什么也没做。 numberofrowsinsection 未被调用。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _faqData.count;
}
我不知道该怎么办。以前从来没有过这个(通常我在 Swift 中编码,也许我在 Objective-C 中忘记了什么)?
有谁知道我做错了什么?
非常感谢!
能否尝试将 tableView 作为强参考? 类似于:
@property (nonatomic, strong) IBOutlet UITableView *tableView