記事のメイン リストがあり、クリックすると読み取りビュー コントローラーに移動し、そのビュー コントローラーが位置を保持する NSNumber プロパティを使用して、ユーザーの読み取りの進行状況を追跡します。戻るボタンを押したときにこの位置をルートビューコントローラーに戻して更新したいのですが(進行状況を表示できるようにするため)、デリゲートが機能していないようです。
読み取りビューの .h ファイル:
@property (nonatomic, weak) id<UpdateProgressDelegate> delegate;
...
@protocol UpdateProgressDelegate <NSObject>
@required
- (void)finishedReadingWithPosition:(NSNumber *)position;
@end
.m ファイル内:
- (void)viewDidDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
if ([self.delegate respondsToSelector:@selector(finishedReading:)]) {
[self.delegate finishedReadingWithPosition:self.position];
}
}
私のルートビューでは(実際にプロトコルを実装していることに注意してください):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ReadBasicArticleSegue"] || [segue.identifier isEqualToString:@"ReadFullArticleSegue"]) {
ReadingViewController *destination = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
self.rowOfLastSelectedCell = @(indexPath.row);
Article *article = self.articles[[self.rowOfLastSelectedCell intValue]];
// Set ReadingViewController's variables so the selected article can be read
destination.textToRead = [article.body componentsSeparatedByString:@" "];
destination.wordsPerMinute = @(1500);
destination.numberOfWordsShown = @(3);
destination.delegate = self;
}
}
と...
- (void)finishedReadingWithPosition:(NSNumber *)position {
Article *article = [self.articles objectAtIndex:[self.rowOfLastSelectedCell intValue]];
article.position = position;
[self.tableView reloadData];
}
私は自分が間違っていることを理解していません。戻るボタンを押しても、ルート ビュー コントローラーの進行状況インジケーターは 0% のままです。