mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-04-27 15:07:44 +00:00
restore selected post
This commit is contained in:
parent
4ce730490c
commit
eca3042fcf
1 changed files with 21 additions and 5 deletions
|
|
@ -38,6 +38,7 @@
|
||||||
@property (nonatomic, copy) NSString *blogStatusText;
|
@property (nonatomic, copy) NSString *blogStatusText;
|
||||||
@property (nonatomic, strong) NSDate *blogStatusDate;
|
@property (nonatomic, strong) NSDate *blogStatusDate;
|
||||||
@property (nonatomic, strong) NSTimer *blogStatusTimer;
|
@property (nonatomic, strong) NSTimer *blogStatusTimer;
|
||||||
|
@property (nonatomic, strong) NSIndexPath *selectedIndexPath;
|
||||||
@property (nonatomic, weak) NSLayoutConstraint *titleViewWidthConstraint;
|
@property (nonatomic, weak) NSLayoutConstraint *titleViewWidthConstraint;
|
||||||
@property (nonatomic, weak) NSLayoutConstraint *titleViewHeightConstraint;
|
@property (nonatomic, weak) NSLayoutConstraint *titleViewHeightConstraint;
|
||||||
@property (nonatomic, weak) NSLayoutConstraint *titleLabelTopConstraint;
|
@property (nonatomic, weak) NSLayoutConstraint *titleLabelTopConstraint;
|
||||||
|
|
@ -197,9 +198,13 @@ static const NSUInteger SectionPublished = 1;
|
||||||
if (self.clearsSelectionOnViewWillAppear && self.tableView.indexPathForSelectedRow) {
|
if (self.clearsSelectionOnViewWillAppear && self.tableView.indexPathForSelectedRow) {
|
||||||
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
|
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
|
||||||
}
|
}
|
||||||
if (!self.postCollections) {
|
PMKPromise *postP = self.postCollections ? [PMKPromise promiseWithValue:self.postCollections] : [self requestPostsWithCaching:YES];
|
||||||
[self requestPostsWithCaching:YES];
|
postP.then(^{
|
||||||
}
|
if (self.selectedIndexPath && [self postForIndexPath:self.selectedIndexPath]) {
|
||||||
|
[self.tableView selectRowAtIndexPath:self.selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
|
||||||
|
self.selectedIndexPath = nil;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated {
|
- (void)viewDidAppear:(BOOL)animated {
|
||||||
|
|
@ -265,11 +270,19 @@ static const NSUInteger SectionPublished = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PostCollection *)postCollectionForSection:(NSInteger)section {
|
- (PostCollection *)postCollectionForSection:(NSInteger)section {
|
||||||
return [self collectionsForTableView][section];
|
NSArray *collections = [self collectionsForTableView];
|
||||||
|
if (section < collections.count) {
|
||||||
|
return collections[section];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Post *)postForIndexPath:(NSIndexPath *)indexPath {
|
- (Post *)postForIndexPath:(NSIndexPath *)indexPath {
|
||||||
return [self postCollectionForSection:indexPath.section].posts[indexPath.row];
|
PostCollection *collection = [self postCollectionForSection:indexPath.section];
|
||||||
|
if (indexPath.row < collection.posts.count) {
|
||||||
|
return collection.posts[indexPath.row];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMutableArray *)drafts {
|
- (NSMutableArray *)drafts {
|
||||||
|
|
@ -491,16 +504,19 @@ static const NSUInteger SectionPublished = 1;
|
||||||
|
|
||||||
static NSString *const StateRestorationBlogStatusDateKey = @"blogStatusDate";
|
static NSString *const StateRestorationBlogStatusDateKey = @"blogStatusDate";
|
||||||
static NSString *const StateRestorationBlogStatusTextKey = @"blogStatusText";
|
static NSString *const StateRestorationBlogStatusTextKey = @"blogStatusText";
|
||||||
|
static NSString *const StateRestorationTableViewSelectedIndexPathKey = @"tableView.indexPathForSelectedRow";
|
||||||
|
|
||||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||||
[coder encodeObject:self.blogStatusDate forKey:StateRestorationBlogStatusDateKey];
|
[coder encodeObject:self.blogStatusDate forKey:StateRestorationBlogStatusDateKey];
|
||||||
[coder encodeObject:self.blogStatusText forKey:StateRestorationBlogStatusTextKey];
|
[coder encodeObject:self.blogStatusText forKey:StateRestorationBlogStatusTextKey];
|
||||||
|
[coder encodeObject:self.tableView.indexPathForSelectedRow forKey:StateRestorationTableViewSelectedIndexPathKey];
|
||||||
[super encodeRestorableStateWithCoder:coder];
|
[super encodeRestorableStateWithCoder:coder];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||||
self.blogStatusDate = [coder decodeObjectForKey:StateRestorationBlogStatusDateKey];
|
self.blogStatusDate = [coder decodeObjectForKey:StateRestorationBlogStatusDateKey];
|
||||||
self.blogStatusText = [coder decodeObjectForKey:StateRestorationBlogStatusTextKey];
|
self.blogStatusText = [coder decodeObjectForKey:StateRestorationBlogStatusTextKey];
|
||||||
|
self.selectedIndexPath = [coder decodeObjectForKey:StateRestorationTableViewSelectedIndexPathKey];
|
||||||
[super decodeRestorableStateWithCoder:coder];
|
[super decodeRestorableStateWithCoder:coder];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue