gpt4 book ai didi

ios - RightBarButtonItem 仅显示为非事件状态

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:58 27 4
gpt4 key购买 nike

尝试将刷新按钮显示为 rightBarButtonItem 时遇到一个奇怪的问题。

总之,我已经实现了,但是运行应用程序时什么也看不到。但是,当我单击 Storyboard Debug --> View Debugging --> Capture View Hierarchy 时。我可以看到一个似乎不活动且隐藏的刷新按钮。我不知道为什么。

enter image description here

viewcontrol 实际上是通过自定义 pageviewcontroller 推送的。

- (void)viewDidLoad {
[super viewDidLoad];

self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];

TNViewController *initialViewController = [self viewControllerAtIndex:currentIndex];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(refreshClicked:)];
initialViewController.navigationItem.rightBarButtonItem = refreshButton;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:initialViewController];

NSArray *viewControllers = [NSArray arrayWithObject:navigationController];

[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];

for (UIView *subview in self.pageController.view.subviews) {
if ([subview isKindOfClass:[UIPageControl class]]) {
UIPageControl *pageControl = (UIPageControl *)subview;
pageControl.pageIndicatorTintColor = [UIColor blackColor];
pageControl.currentPageIndicatorTintColor = [utils colorFromHexString:@"#AA3635"];
pageControl.numberOfPages = _news.count;
pageControl.backgroundColor = [UIColor whiteColor];
}
}
self.edgesForExtendedLayout = UIRectEdgeTop;
}

请问我错过了什么?

最佳答案

因为您要将它添加到 uiviewcontroller,所以您需要创建 UINavigationBar、UINavigationItem 和 UIButton。然后将 UIButton 添加到 UINavigationItem,然后将 UINavigationItem 添加到 UINavigationBar:

   _navBar = [[UINavigationBar alloc] init];
[_navBar setFrame:CGRectMake(0,0,self.view.bounds.size.width,52)];
[self.view addSubview:_navBar];
UINavigationItem *navItem = [[UINavigationItem alloc]initWithTitle:@""];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshClicked:)];
[navItem setLeftBarButtonItem:barButton];

[_navBar setItems:@[navItem]];

此代码来自此处找到的答案:

adding barButtonItems to a UINavigationBar without a Navigation Controller

希望这对您有所帮助。

关于ios - RightBarButtonItem 仅显示为非事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428898/

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