uitableview - TableView :cellForRowAtIndexPath: in iOS Today Widget with UITableViewController called once

标签 uitableview ios8-today-widget today-extension

我正在尝试在 UIViewController 子类的 Today Widget 扩展中显示数据。项目(行)的数量总是 3tableView: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

最佳答案

如果您使用的是 Storyboard,请检查 TableView 内容是否设置为“动态原型(prototype)”(而不是“静态单元格”)

enter image description here

关于uitableview - TableView :cellForRowAtIndexPath: in iOS Today Widget with UITableViewController called once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28951554/

相关文章:

ios - iOS UITableView 中的下拉列表

ios - 今天的 Widget 每次刷新都会使用更多的内存,然后最终崩溃

ios - 尝试设置今日小部件时出现 Xcode 错误

iOS - 今天扩展 'show more' 和 'show less' 状态不正确。折叠显示 'show less' - 需要多次按下才能修复

ios - 在主机应用程序和今日扩展程序之间共享用户生成的图像的最佳方式是什么

ios - 带有今天扩展的 AVAudioEngine

swift - swift 从 do-catch 语句中获取变量

ios - 在 TableView 中仅显示一次 json 数组中的重复元素 swift

iphone - 重新创建预览歌曲的 iTunes(iOS 应用程序)tableViewCell

ios - CoreData 扩展 - 将模型添加到目标时为 'Use of Undeclared Identifier'