Skip to content

Commit

Permalink
Merge pull request #7 from lxcid/master
Browse files Browse the repository at this point in the history
Attempts to fix issue #6.
  • Loading branch information
honcheng committed Nov 26, 2012
2 parents fa1a7d3 + 07ede31 commit 19a2516
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions PaperFoldMenuController/PaperFoldMenuController.m
Expand Up @@ -40,7 +40,7 @@ @interface PaperFoldMenuController ()
@property (nonatomic, weak) ShadowView *menuTableViewSideShadowView;
@property (nonatomic, assign) float menuWidth;
@property (nonatomic, assign) int numberOfFolds;
@property (nonatomic, strong) NSBlockOperation *viewDidLoadBlockOperation;
@property (nonatomic, strong) NSMutableArray *viewDidLoadBlocks;
/**
* This method reloads the menu on the left
* and refresh the screenshot of the menu used in
Expand All @@ -51,11 +51,11 @@ - (void)reloadMenu;

@implementation PaperFoldMenuController

- (NSBlockOperation *)viewDidLoadBlockOperation {
if (_viewDidLoadBlockOperation == nil) {
self.viewDidLoadBlockOperation = [[NSBlockOperation alloc] init];
- (NSMutableArray *)viewDidLoadBlocks {
if (_viewDidLoadBlocks == nil) {
self.viewDidLoadBlocks = [[NSMutableArray alloc] init];
}
return _viewDidLoadBlockOperation;
return _viewDidLoadBlocks;
}

+ (BOOL)automaticallyNotifiesObserversOfSelectedViewController
Expand Down Expand Up @@ -102,17 +102,13 @@ - (void)setSelectedIndex:(NSUInteger)theSelectedIndex
if (!self.isViewLoaded)
{
__weak typeof(self) theWeakSelf = self;
[self.viewDidLoadBlockOperation addExecutionBlock:^{
[self.viewDidLoadBlocks addObject:[^{
__strong typeof(self) theStrongSelf = theWeakSelf;
if (theStrongSelf == nil) {
return;
}
// This is ran on a seperate thread, which is NSBlockOperation addExecutionBlock: behavior.
// It shouldn't cause any issue though but noted here just in case anyone face any issue.
// This also means observing selectedIndex or selectedViewController are not gaurentee to be
// running on main thread.
theStrongSelf.selectedIndex = theSelectedIndex;
}];
} copy]];
}
else
{
Expand Down Expand Up @@ -222,8 +218,10 @@ - (void)viewDidLoad
[self.paperFoldView.leftFoldView addSubview:menuTableViewSideShadowView];
self.menuTableViewSideShadowView = menuTableViewSideShadowView;

[self.viewDidLoadBlockOperation start];
self.viewDidLoadBlockOperation = nil;
for (void (^theBlock)(void) in self.viewDidLoadBlocks) {
theBlock();
}
self.viewDidLoadBlocks = nil;
}

- (void)setViewControllers:(NSMutableArray *)viewControllers
Expand Down

0 comments on commit 19a2516

Please sign in to comment.