を含む iOS Today 拡張機能をプログラミングUITableView
しています。私の考えは、拡張機能がロードされたときにファイルからアーカイブされたデータをロードし、UI にデータを表示し、widgetPerformUpdateWithCompletionHandler
.
リモート コンテンツがフェッチされると、ローカル アーカイブ ファイルに保存さreloadData
れ、UITableView
. UITableView
も に応答しますtableView:didSelectRowAtIndexPath
。ユーザーが行の 1 つをタップすると、Safari が起動します。
しかし、拡張機能が読み込まれると、システムは UI を表示する代わりに以前のスナップショットを使用することに気付きました。それは結構です、私はそれがパフォーマンス上の理由であることを知っています。ただし、スナップショットは UI イベントを受け取ることができませんUITableView
。これは、ユーザーが各行をタップできるようになるまで、拡張機能が表示されてから遅延が発生することを意味します。
スナップショットが表示される時間を短縮する方法を知っている人はいますか? widgetPerformUpdateWithCompletionHandler
拡張機能がロードされたときに、Today が for 拡張機能を呼び出さないようです。
私が使用しているサンプルコードは次のとおりです。
@implementation TodayViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.preferredContentSize = CGSizeMake(0, 0);
[self loadArchivedData];
self.preferredContentSize = CGSizeMake(0, self.stories.count * kCellHeight);
[self.tableView registerNib:[UINib nibWithNibName:@"RHNTodayCell" bundle:nil] forCellReuseIdentifier:@"RHNTodayCell"];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.stories.count;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RHNTodayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHNTodayCell" forIndexPath:indexPath];
NSDictionary *story = self.stories[indexPath.row];
cell.titleLabel.text = story[@"title"];
cell.scoreLabel.text = [NSString stringWithFormat:@"%d", (int)[story[@"score"] integerValue]];
cell.commentLabel.text = [NSString stringWithFormat:@"%d", (int)[story[@"kids"] count]];
cell.nameLabel.text = story[@"by"];
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *story = self.stories[indexPath.row];
[self.extensionContext openURL:[NSURL URLWithString:story[@"url"]] completionHandler:nil];
}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
completionHandler(NCUpdateResultNewData);
[[RemoteAPI sharedClient] asyncFetchRemoteData:(NSArray *response) {
[self saveArchiveFilesWithResponse: response];
[self loadArchivedData];
self.preferredContentSize = CGSizeMake(0, self.stories.count * kCellHeight);
[self.tableView reloadData];
completionHandler(NCUpdateResultNewData);
}];
}
@end