Я пытаюсь отобразить данные в расширении Today Widget в подклассе UIViewController. Количество элементов (строк) всегда равно , но tableView:cellForRowAtIndexPath:
вызывается только один раз.tableView: cellForRowAtIndexPath: в iOS Today Widget с UITableViewController называется один раз
Я проверил все, но не могу найти ошибку.
Любые предложения? Спасибо!
#import "TodayViewController.h"
#import "FLWAccount.h"
#import "FLWAccountTableViewCell.h"
#import "FLWAuthManager.h"
#import <NotificationCenter/NotificationCenter.h>
@interface TodayViewController() <NCWidgetProviding, UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, readwrite, weak) IBOutlet UITableView
*tableView;
@end
@implementation TodayViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 79.0f;
self.tableView.rowHeight = 79.0f;
[self updatePreferredContentSize];
[self.tableView reloadData];}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
[[FLWAuthManager sharedManager] updateAllAccountsWithCompletion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self updatePreferredContentSize];
[self.tableView reloadData];
completionHandler(NCUpdateResultNewData);
});
}]; }
#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count = [FLWAuthManager sharedManager].accounts.count;
return count; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FLWAccountTableViewCell *cell = (FLWAccountTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FLWAccountTableViewCell" forIndexPath:indexPath];
cell.account = [FLWAuthManager sharedManager].accounts[indexPath.row];
return cell; }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 79.0f; }
- (void)updatePreferredContentSize {
NSInteger count = [FLWAuthManager sharedManager].accounts.count;
self.preferredContentSize = CGSizeMake(self.preferredContentSize.width, 79.0f * count); }
@end
Если 'Tableview: cellForRowAtIndexPath:' является вызывается только один раз, это говорит вам, что количество элементов на самом деле не на самом деле. 3. Вы проверили, что 'tableView: numberOfRowsInSection:' возвращает 3? –
Я проверил его, это точно 3. В 'updatePreferredContentSize' я устанавливаю размер виджета и там тоже 3, а размер виджета в три раза больше, чем только отображаемая ячейка –
Является ли' tableView: numberOfRowsInSection : 'вызов? Я так не думаю. –