gpt4 book ai didi

objective-c - 无法覆盖简单方法

转载 作者:行者123 更新时间:2023-11-29 13:22:07 24 4
gpt4 key购买 nike

我创建了一个包含两个 ViewController 的新项目,并导入了一个将 ViewController 从右向左推送而不是 LTR 的类,但无法使用它。我可以看到 UIRightToLeft.m 中的 pushViewController 没有被调用,我不明白为什么。我的主要目标是让它与 RTL 动画一起工作。

#import "UIRightToLeft.h"

@implementation UIRightToLeft

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (!self)
return nil;
return self;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"pushViewController");
// Add the viewController and a fake controller without animation. Then pop the fake controller with animation.
UIViewController *fakeController = [[UIViewController alloc] init] ;
[super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO];
[super popViewControllerAnimated:animated];
}

- (void)popViewControllerAnimatedStep2:(UIViewController *)viewController
{
// Push the new top controller with animation
[super pushViewController:viewController animated:YES];
// Remove the view that should have been popped
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
NSLog(@"popViewControllerAnimated");

if (animated)
{
// Save the controller that should be on top after this pop operation
UIViewController *newTopController = [[self viewControllers] objectAtIndex:[[self viewControllers] count]-2];
// Remove it from the stack. Leave the view that should be popped on top
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
// Schedule the next step
[self performSelector:@selector(popViewControllerAnimatedStep2:) withObject:newTopController afterDelay:0];
return [arr objectAtIndex:[arr count]-1];
}
return [super popViewControllerAnimated:NO];
}

@end

ViewController.m:

#import "ViewController.h"
#import "UIRightToLeft.h"
#import "SecondViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)pressMe:(UIButton *)sender {
SecondViewController *next = [[SecondViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
}

@end

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)pressMe:(UIButton *)sender;

@end

(在我的 ViewController 中,只有一个按钮被拖到第二个 ViewController 上)

最佳答案

查看错误日志后,我认为您实际上需要拥有导航 Controller 子类 UIRightToLeft。

如果您使用的是 Storyboard,请选择您的导航 Controller 并将自定义类设置为 UIRightToLeft。

关于objective-c - 无法覆盖简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14128622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com