mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-04-24 14:37:42 +00:00
weakify self in view controllers
This commit is contained in:
parent
72d825efc0
commit
3a8e3b70eb
3 changed files with 14 additions and 0 deletions
|
|
@ -277,7 +277,9 @@
|
|||
[items replaceObjectAtIndex:[items indexOfObject:saveItem] withObject:indicatorItem];
|
||||
[self.toolbar setItems:items animated:NO];
|
||||
|
||||
__weak __typeof__(self) welf = self;
|
||||
return savePromise.then(^{
|
||||
__typeof__(self) self = welf;
|
||||
NSLog(@"%@ post at path %@", verb, path);
|
||||
|
||||
// update our post because "new" may have changed, which is essential to correct operation
|
||||
|
|
@ -290,6 +292,7 @@
|
|||
NSLog(@"Failed to %@ post at path %@: %@ %@", verb, path, error.localizedDescription, error.userInfo);
|
||||
return error;
|
||||
}).finally(^{
|
||||
__typeof__(self) self = welf;
|
||||
self.textView.editable = YES;
|
||||
self.savePromise = nil;
|
||||
[items replaceObjectAtIndex:[items indexOfObject:indicatorItem] withObject:saveItem];
|
||||
|
|
@ -314,7 +317,9 @@
|
|||
|
||||
- (IBAction)publishOrUnpublish:(id)sender {
|
||||
// TODO: prevent changes while publishing
|
||||
__weak __typeof__(self) welf = self;
|
||||
[self savePost].then(^{
|
||||
__typeof__(self) self = welf;
|
||||
PMKPromise *promise = nil;
|
||||
Post *post = self.modifiedPost;
|
||||
if (post.draft) {
|
||||
|
|
@ -395,7 +400,9 @@
|
|||
NSURL *currentURL = self.modifiedPost.url;
|
||||
if (currentURL) {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TODO" message:@"show a web browser" preferredStyle:UIAlertControllerStyleAlert];
|
||||
__weak __typeof__(self) welf = self;
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
__typeof__(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}]];
|
||||
[self presentViewController:alertController animated:YES completion:nil];
|
||||
|
|
|
|||
|
|
@ -200,7 +200,9 @@ static const NSUInteger SectionPublished = 1;
|
|||
[self requestStatusWithoutCaching];
|
||||
}).catch(^(NSError *error) {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
|
||||
__weak __typeof__(self) welf = self;
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
__typeof__(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}]];
|
||||
[self presentViewController:alertController animated:YES completion:nil];
|
||||
|
|
@ -220,7 +222,9 @@ static const NSUInteger SectionPublished = 1;
|
|||
[controller configureWithPost:post];
|
||||
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
|
||||
controller.navigationItem.leftItemsSupplementBackButton = YES;
|
||||
__weak __typeof__(self) welf = self;
|
||||
controller.postUpdatedBlock = ^(Post *post) {
|
||||
__typeof__(self) self = welf;
|
||||
BOOL (^isThisPost)(Post *, NSUInteger, BOOL *) = ^BOOL(Post *p, NSUInteger idx, BOOL *stop) {
|
||||
return [p.objectID isEqualToString:post.objectID];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,9 +21,12 @@
|
|||
|
||||
if (self.initialRequest) {
|
||||
if (self.promise) {
|
||||
__weak __typeof__(self) welf = self;
|
||||
self.promise.then(^{
|
||||
__typeof__(self) self = welf;
|
||||
[self.webView loadRequest:self.initialRequest];
|
||||
}).finally(^{
|
||||
__typeof__(self) self = welf;
|
||||
self.promise = nil;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue