【问题标题】:iOS 8 Today widget doesn't show up when loadediOS 8 Today 小部件在加载时不显示
【发布时间】:2015-02-04 21:51:33
【问题描述】:

我创建了简单的时间表小部件,但是当我尝试在 iOS 模拟器中对其进行测试时,它会显示类似

时间表[4012:108619] 未能从 3965 继承 CoreMedia 权限:(null)

并且小部件没有显示出来。 这是我的代码。

#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>

@interface TodayViewController () <NCWidgetProviding, UITableViewDataSource, UITableViewDelegate>


@end

@implementation TodayViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableCell"];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 7;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
    // Perform any setup necessary in order to update the view.

    // If an error is encountered, use NCUpdateResultFailed
    // If there's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData

        completionHandler(NCUpdateResultNewData);
    }

    @end

【问题讨论】:

    标签: ios objective-c xcode6 ios8-extension notificationcenter


    【解决方案1】:

    该消息一直出现在今天的小部件中,通常并不表示实际上有任何问题。除非您遇到某种您没有提及的问题,否则请忽略它。

    您的小部件未显示的原因是您的代码没有说明您需要多少空间。您需要设置self.preferredContentSize。使用小部件中的表格视图,您通常会执行以下操作:

    self.preferredContentSize = CGSizeMake(self.preferredContentSize.width, self.objects.count * 44.0);
    

    将 self.objects 替换为您用于表格数据的任何数组,并将 44 替换为您的单元格高度。

    您的代码使用了 7 行,这可能太多了。有关原因的讨论,请参阅 Issue in Widgets in landscape mode。

    【讨论】:

    • 但我在 iOS 模拟器中只看到小部件的名称。
    • 我明白了,你应该提到这一点。答案已更新。
    • 奇怪,但同样的事情发生了。我可以在小部件中使用自定义 UITableView 高度吗?
    • 您可以在任何使用单元格的地方使用自定义单元格高度。你用什么方法设置了首选高度?
    • 我在界面生成器中设置了。
    【解决方案2】:

    Swift 4 版本:

    preferredContentSize = CGSize(width: preferredContentSize.width, 
                                  height: CGFloat(objects.count) * 44.0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多