- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为 UINavigation Controller 实现自定义动画。
我在 Appdelegate 中添加了一些属性:
@interface MyAppDelegate : UIResponder <UIApplicationDelegate> {
...
// for custrom navigation transition animation
@property (strong, nonatomic) UINavigationController *AppNavigationController;
...
@end
在 didFinishLaunchingWithOptions 中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
self.AppNavigationController = (UINavigationController *)((REFrostedViewController *)self.window.rootViewController).contentViewController;
MyNavigationControllerDelegate * naviDelegate = [[MyNavigationControllerDelegate alloc] init];
self.AppNavigationController.delegate = naviDelegate;
}
...
}
调试时,到目前为止我可以看到委托(delegate):
(lldb) po self.AppNavigationController
<UINavigationController: 0x14f52bb90>
(lldb) po self.AppNavigationController.delegate
<MyNavigationControllerDelegate: 0x17424c5a0>
当我的主视图 Controller 加载时,我仍然可以看到
(lldb) po 0x14f52bb90
<UINavigationController: 0x14f52bb90>
但是当尝试访问 0x14f52bb90 它的委托(delegate)时,
(lldb) po [0x14f52bb90 delegate]
2015-02-28 18:54:14.724 MyApp[1995:489717] *** -[MyNavigationControllerDelegate respondsToSelector:]: message sent to deallocated instance 0x17424c5a0
0x000000017424c5a0
我不确定委托(delegate)被释放的原因,以及如何修复它。有什么想法吗?
MyNavigationControllerDelegate 初始化代码:
-(id)init {
self = [super init];
if (self) {
self.pushAnimator = [[PushAnimator alloc] init];
self.popAnimator = [[PopAnimator alloc] init];
UIApplication * app = [UIApplication sharedApplication];
MyAppDelegate *appDelegate = (MyAppDelegate *)app.delegate;
self.navigationController = appDelegate.AppNavigationController;
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.navigationController.view addGestureRecognizer:panRecognizer];
}
return self;
}
以及进一步的崩溃跟踪:
(lldb) bt
* thread #1: tid = 0x778f5, 0x0000000184a72440 CoreFoundation`___forwarding___ + 968, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x184a72440)
* frame #0: 0x0000000184a72440 CoreFoundation`___forwarding___ + 968
frame #1: 0x0000000184976b6c CoreFoundation`_CF_forwarding_prep_0 + 92
frame #2: 0x00000001892d1d4c UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 908
frame #3: 0x00000001892d16dc UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 640
frame #4: 0x00000001892d13fc UIKit`-[UINavigationController __viewWillLayoutSubviews] + 56
frame #5: 0x00000001892d137c UIKit`-[UILayoutContainerView layoutSubviews] + 200
最佳答案
我的猜测是,您的 AppNavigationController
上的 delegate
属性定义为 @property(assign)
(或者没有任何修饰符,默认为 assign
),因此当 -application:didFinishLoadingWithOptions
完成时,delegate
被释放,因为它没有在任何地方保留。
如果是这种情况,您可以使用 @property(strong)
修复它。
编辑
UINavigationController
属性delegate
被定义为assign
,所以你需要在其他地方保留delegate,我建议这样做:
我的应用程序委托(delegate)
@interface MyAppDelegate : UIResponder <UIApplicationDelegate> {
...
@property(strong) MyNavigationControllerDelegate* naviDelegate;
...
@end
didFinishlaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
self.AppNavigationController = (UINavigationController *)((REFrostedViewController *)self.window.rootViewController).contentViewController;
self.naviDelegate = [[MyNavigationControllerDelegate alloc] init];
self.AppNavigationController.delegate = self.naviDelegate;
...
}
关于ios - 我的 UINavigationControllerDelegate 在应用加载主视图后被取消了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780995/
我已经建立了一个非常简单的项目,没有 Storyboard,一个窗口和一个 UINavigationController,其中包含一个普通的旧 UIViewController 作为 rootView
UINavigationControllerDelegate 只有 2 个委托(delegate)方法可以使用: navigationController:willShowViewController
更新到正确的版本,因为得到了答案。 我想在导航 View Controller 弹出/推送时做淡入/淡出动画,然后我实现一个 BaseViewController: class BaseViewCon
我的代码: 导航器.m - (void)newPushPage:(UIViewController *)controller { [self pushViewController:contro
我有一个 View Controller ,在其中实现 UIImagePickerDelegate 和 UINavigationControllerDelegate,以便从图库或相机获取图像。选择图像
我想为 UINavigation Controller 实现自定义动画。 我在 Appdelegate 中添加了一些属性: @interface MyAppDelegate : UIResponder
我正在尝试在从自定义 UINavigationController 类推送/弹出 viewController 时进行自定义转换。我正在实现 UINavigationControllerDelegat
我在 UINavigationController 堆栈中有一个用于推送和弹出事件的自定义动画转换,我只想将该自定义动画应用于特定的推送事件——例如,在推送 RandomViewController4
答案:简单语法错误 - 设置委托(delegate)时,它应该读取 SomeNavigationController.delegate = self,而不是 SomeNavigationControl
所以我开始着手创建自定义插入/弹出转换,第一次插入转换时一切正常,但是当我尝试插入另一个 View Controller 时,我根本看不到任何动画。 Here is a sample project
(XCode 8.1,Swift 3。github 中的示例 https://github.com/SuperTango/UINavigationControllerNoNavbar 在“byhand
短:实现 func navigationController(_ navigationController: UINavigationController, animationControllerFo
我正在尝试使用 UIImagePickerController 从图库中挑选一张图片。 如果我的 View Controller 没有提到 UINavigationControllerDelegate
class ViewController: UIViewController, UINavigationControllerDelegate { override func viewDid
有没有办法让 View Controller 从内部转换出来: - (void)navigationController:(UINavigationController *)navigationCon
DetailViewController MasterViewController ViewController 目前,我通过让 ViewController 类中的一个变量指向 DetailVi
func openGallery(sender: AnyObject) { var imagePicker = UIImagePickerController() imagePicke
我正在开发一个包含 WYPopoverController 的应用程序,它在应有的地方工作得很好。我想在两个 Controller 之间添加自定义动画,而不是内置 push/pop。 在包含 FROM
如果您拖动 UIViewController 的边缘以在 UINavigationController 中开始交互式弹出转换,当前下方的 UIViewController 具有 viewWillApp
弹出到不支持当前方向的 View Controller 时,未调用 UINavigationControllerDelegate 方法。 我有一个 UINavigationController 作为我
我是一名优秀的程序员,十分优秀!