3

我正在尝试在 UIViewController 子类的 Today Widget 扩展中显示数据。项目(行)的数量始终为3,但tableView:cellForRowAtIndexPath:仅调用一次。

我已经仔细检查了所有内容,但找不到错误。

有什么建议么?谢谢!

#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
4

1 回答 1

1

如果您使用情节提要,请检查表格视图内容是否设置为“动态原型”(而不是“静态单元格”)

在此处输入图像描述

于 2015-03-11T10:58:12.283 回答