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