大佬教程收集整理的这篇文章主要介绍了UINavigationController和UINavigationBarDelegate.ShouldPopItem()与MonoTouch,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现最吸引人的方法是在UINavigationBar的代理上覆盖ShouldPopItem().
现在,这里有一个很相似的问题:iphone navigationController : wait for uialertview response before to quit the current view
还有一些类似性质的其他问题,例如:
Checking if a UIViewController is about to get Popped from a navigation stack?
和How to tell when back button is pressed in a UINavigationControllerStack
所有这些状态“子类UINavigationController”作为可能的答案.
那就是这样一个读类似子类的UINavigationController一般不是一个好主意:
Monotouch: UINavigationController,override initWithRootViewController
apple docs还说UINavigationController不是要进行子类化的.
另外还有一些人声称,在使用UINavigationController时,不重要的ShouldPopItem()是不可能的,因为它不允许将一个自定义/子类的UINavigationBarDelegate分配给UINavigationBar.
我的子类化尝试没有工作,我的自定义代表不被接受.
我也读过某个地方可能会在我的自定义UINavigationController中实现ShouldPopItem(),因为它将自己指定为它的UINavigationBar的Delegate.
没什么惊喜,这没有办法. UINavigationController的子类如何知道属于UINavigationBarDelegate的方法.它被拒绝:“找不到适当的方法来覆盖”.删除“覆盖”关键字已编译,但该方法被完全忽略(如预期).我认为,使用Obj-C可以实现几个协议(类似于C#AFAIK中的接口)来实现.不幸的是,UINavigationBarDelegate不是一个接口,而是MonoTouch中的一个类,所以这似乎是不可能的.
我几乎在这里迷路了当UINavigationBar的代理由UINavigationController控制时,如何覆盖ShouldPopItem()?还有其他方法可以弹出一个UIAlertView并等待它的结果可能会弹出导航堆栈?
这实现了“你确定要退出吗?当按下后退按钮时发出警报,请从代码修改:http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller/
原来,如果您在CustomNavigationController中实现UINavigationBarDelegate,可以使用shouldPopItem方法:
CustomNavigationController.h:
#import <Foundation/Foundation.h> @interface CustomNavigationController : UINavigationController <UIAlertViewDelegate,UINavigationBarDelegate> { BOOL alertViewClicked; BOOL regularPop; } @end
CustomNavigationController.m:
#import "CustomNavigationController.h" #import "SetTingsTableController.h" @implementation CustomNavigationController - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item { if (regularPop) { regularPop = falSE; return YES; } if (alertViewClicked) { alertViewClicked = falSE; return YES; } if ([self.topViewController isMemberOfClass:[SetTingsTableViewController class]]) { UIAlertView * exitAlert = [[[UIAlertView alloc] initWithtitle:@"Are you sure you want to quit?" message:nil delegate:self cancelButtontitle:@"Cancel" otherButtontitles:@"Yes",nil] autorelease]; [exitAlert show]; return NO; } else { regularPop = TRUE; [self popViewControllerAnimated:YES]; return NO; } } -(void)alertView:(UIAlertView *)alertView clickedButtonATindex:(NSInteger)buttonIndex { if (buttonIndex == 0) { //Cancel button } else if (buttonIndex == 1) { //Yes button alertViewClicked = TRUE; [self popViewControllerAnimated:YES]; } } @end
“regularPop”bool的奇怪的逻辑是因为某些原因只是在shouldPopItem上返回“YES”只会弹出导航栏,而不是与navBar关联的视图 – 为此,您必须直接调用popViewControllerAnimated(然后调用shouldPopItem为其逻辑的一部分)
以上是大佬教程为你收集整理的UINavigationController和UINavigationBarDelegate.ShouldPopItem()与MonoTouch全部内容,希望文章能够帮你解决UINavigationController和UINavigationBarDelegate.ShouldPopItem()与MonoTouch所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。