From 96e1fe74e58543526174adf1ddf4643bd41e18bd Mon Sep 17 00:00:00 2001 From: liufengting Date: Sun, 27 Nov 2016 12:02:37 +0800 Subject: [PATCH] fix a bug: doneblock not working --- .gitignore | 4 ++- FTPopMenu/FTPopMenu.h | 23 +++++++------ FTPopMenu/FTPopTableViewController.m | 20 +++++------ .../FTPopMenu.xcodeproj/project.pbxproj | 6 +++- FTPopMenuDemo/FTPopMenu/ViewController.m | 34 +++++++++++-------- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 79d9331..7eb046d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ # # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore +.DS_Store + ## Build generated build/ DerivedData @@ -33,7 +35,7 @@ xcuserdata # you should judge for yourself, the pros and cons are mentioned at: # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control # -# Pods/ +Pods/ # Carthage # diff --git a/FTPopMenu/FTPopMenu.h b/FTPopMenu/FTPopMenu.h index a75ee60..f22bbd6 100644 --- a/FTPopMenu/FTPopMenu.h +++ b/FTPopMenu/FTPopMenu.h @@ -39,7 +39,7 @@ title:(NSString *)title menuArray:(NSArray *)menuArray menuImageNameArray:(NSArray *)menuImageNameArray - preferedWidth:(CGFloat )perferedWidth + perferedWidth:(CGFloat )perferedWidth rowHeight:(CGFloat )rowHeight tintColor:(UIColor *)tintColor doneBlock:(void(^)(NSInteger selectedIndex))doneBlock @@ -69,16 +69,17 @@ cancelBlock:(void(^)())cancelBlock; -+(void)showFTMenuForViewController:(UIViewController *)sourceViewController - fromBarButtonItem:(UIBarButtonItem *)barButtonItem - title:(NSString *)title - menuArray:(NSArray *)menuArray - menuImageNameArray:(NSArray *)menuImageNameArray - preferedWidth:(CGFloat )perferedWidth - rowHeight:(CGFloat )rowHeight - tintColor:(UIColor *)tintColor - doneBlock:(void(^)(NSInteger selectedIndex))doneBlock - cancelBlock:(void(^)())cancelBlock; +-(void)showForViewController:(UIViewController *)sourceViewController + fromBarButtonItem:(UIBarButtonItem *)barButtonItem + senderView:(UIView *)sender + title:(NSString *)title + tintColor:(UIColor *)tintColor + perferedWidth:(CGFloat )perferedWidth + rowHeight:(CGFloat )rowHeight + menuArray:(NSArray *)menuArray + menuImageNameArray:(NSArray *)menuImageNameArray + doneBlock:(void(^)(NSInteger selectedIndex))doneBlock + cancelBlock:(void(^)())cancelBlock; diff --git a/FTPopMenu/FTPopTableViewController.m b/FTPopMenu/FTPopTableViewController.m index b9cd7b2..0b984dd 100644 --- a/FTPopMenu/FTPopTableViewController.m +++ b/FTPopMenu/FTPopTableViewController.m @@ -202,15 +202,7 @@ - (void)popoverPresentationController:(UIPopoverPresentationController *)popover } - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { - if (_selectedIndex >= 0) { - if (self.doneBlock) { - self.doneBlock(_selectedIndex); - } - }else{ - if (self.cancelBlock) { - self.cancelBlock(); - } - } + } @@ -235,7 +227,15 @@ - (UIViewController *)presentationController:(UIPresentationController *)control - (void)dismiss { [self dismissViewControllerAnimated:YES completion:^{ - + if (_selectedIndex >= 0) { + if (self.doneBlock) { + self.doneBlock(_selectedIndex); + } + }else{ + if (self.cancelBlock) { + self.cancelBlock(); + } + } }]; } diff --git a/FTPopMenuDemo/FTPopMenu.xcodeproj/project.pbxproj b/FTPopMenuDemo/FTPopMenu.xcodeproj/project.pbxproj index 643e7df..c326b0e 100644 --- a/FTPopMenuDemo/FTPopMenu.xcodeproj/project.pbxproj +++ b/FTPopMenuDemo/FTPopMenu.xcodeproj/project.pbxproj @@ -182,7 +182,7 @@ 5A675A6E1CFAAD6B000DAC1C /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = liufengting; TargetAttributes = { 5A675A751CFAAD6B000DAC1C = { @@ -300,8 +300,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -344,8 +346,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; diff --git a/FTPopMenuDemo/FTPopMenu/ViewController.m b/FTPopMenuDemo/FTPopMenu/ViewController.m index 7fb594f..187cc97 100644 --- a/FTPopMenuDemo/FTPopMenu/ViewController.m +++ b/FTPopMenuDemo/FTPopMenu/ViewController.m @@ -55,7 +55,7 @@ - (IBAction)doneAction:(UIBarButtonItem *)sender { [self showFTMenuFromBarButtonItem:sender menuArray:[self menuStringArray] doneBlock:^(NSInteger selectedIndex) { - + NSLog(@"%ld",selectedIndex); } cancelBlock:^{ }]; @@ -109,7 +109,8 @@ - (IBAction)showAction:(UIButton *)sender [self showFTMenuFromView:sender menuArray:[self menuStringArray] doneBlock:^(NSInteger selectedIndex) { - + NSLog(@"%ld",selectedIndex); + }cancelBlock:^{ }]; @@ -141,19 +142,22 @@ - (IBAction)showAction:(UIButton *)sender //Class Method custom -// [FTPopMenu showFTMenuForViewController:self -// fromView:sender -// title:@"I am Title" -// menuArray:[self menuStringArray] -// menuImageNameArray:[self menuImageStringArray] -// preferedWidth:200 -// rowHeight:60 -// tintColor:[UIColor blackColor] -// doneBlock:^(NSInteger selectedIndex) { -// -// }cancelBlock:^{ -// -// }]; + +// [FTPopMenu showFTMenuForViewController:self +// fromView:sender +// title:@"I am Title" +// menuArray:[self menuStringArray] +// menuImageNameArray:[self menuImageStringArray] +// perferedWidth:200 +// rowHeight:60 +// tintColor:[UIColor blackColor] +// doneBlock:^(NSInteger selectedIndex) { +// +// } cancelBlock:^{ +// +// }]; + + }