简体   繁体   English

按下后退按钮,当我将视图控制器从堆栈中弹出时,将丢失我的自定义UIToolBar

[英]Back button pressed, losing my custom UIToolBar when i pop the view controller off the stack

I hope everyone is having a great day so far. 希望到目前为止,大家过得愉快。

I'm running into a problem with my app that I need some help figuring out. 我的应用程序出现问题,需要一些帮助来解决。 I have a view controller (lets call "A") with a custom toolbar which works nicely. 我有一个带有自定义工具栏的视图控制器(我们称其为“ A”),该工具栏效果很好。

When I push a view controller (lets call it "locationsController") from view controller "A" ... 当我从视图控制器“ A”中推送一个视图控制器(我们称其为“ locationsController”)时...

[self.navigationController pushViewController:self.locationsController animated:YES];    

...and I press the back button on the locationsController which closes like this... ...然后我按locationsController上的后退按钮关闭,就像这样...

[self.navigationController popViewControllerAnimated:YES];

I lose my custom toolbar in view controller "A" when locationController is popped. 弹出locationController时,我在视图控制器“ A”中丢失了自定义工具栏。 How do I fix it so I can intercept and call my buildtoolbar method? 如何解决它,以便可以拦截并调用我的buildtoolbar方法?

Also, the locationsController can be pushed/popped from one other view controller so I'll need to determine which view controller is popping locationsController and either fire the buildtoolbar method or do nothing since the other view controller doesn't have a toolbar. 另外,可以从另一个视图控制器中推送/弹出locationsController,因此我需要确定哪个视图控制器正在弹出locationsController并触发buildtoolbar方法或不执行任何操作,因为另一个视图控制器没有工具栏。

view controller "A" is a XIB while locationsController is defined in the storyboard. 情节提要中定义了locationController时,视图控制器“ A”是一个XIB。 the XIB does not Have a toolbar in the view/layout thingy. XIB在视图/布局中没有工具栏。

toolbar code called from viewDidLoad [self buildToolbar]... 从viewDidLoad调用的工具栏代码[self buildToolbar] ...

-(void) buildToolbar{

blah blah blah
self.navigationController.toolbarHidden = NO;
UIBarButtonItem *flexableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
UIBarButtonItem *comments = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Comments-selected.png"] style:UIBarButtonItemStyleDone target:self action:@selector(cameraButtonTapped:)];
UIBarButtonItem *pin = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Pin-straight_60wide.png"] style:UIBarButtonItemStyleDone target:self action:@selector(pinBarButtonItemPressed:)];

NSArray *items = [NSArray arrayWithObjects:customBarButtonItem_right, flexableItem, comments, flexableItem, pin, flexableItem, refresh, nil];
  //  [self.navigationController.toolbar setItems:items animated:YES];
self.toolbarItems = items;
}

Thanks in advance! 提前致谢!

I moved my call to toolbarSetup from viewDidLoad to viewWillAppear. 我将对工具栏设置的调用从viewDidLoad移到了viewWillAppear。 Apparently the 2nd VC's viewDidLoad doesn't fire when the top most VC is popped off the stack. 显然,当最上面的VC从堆栈中弹出时,第二个VC的viewDidLoad不会触发。 viewWillAppear fires followed by viewDidAppear, etc.... 先触发viewWillAppear,再触发viewDidAppear等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在按下按钮时使按钮弹出警报视图并返回主视图控制器? - How Do I Make A Button Get An Alert View To Pop Up When Pressed And Go Back To The Main View Controller? 当导航栏的内置后退按钮被按下时弹出到根视图控制器 - Pop to the root view controller when the navigation bar's built in back button is pressed 在导航控制器中按下“后退”按钮时,是否可能不取消分配视图控制器? - is it possible to not dealloc a view controller when the back button is pressed in a navigation controller? 当按下导航后退按钮时,将值返回到呈现视图控制器 - Return values to presenting view controller when navigation back button pressed 迅速按下导航栏后退按钮时重新加载视图控制器2 - Reloading view controller when navigation bar back button is pressed in swift 2 iOS 7在右侧添加了幻灯片,可以将视图控制器从堆栈中弹出。 是否可以通过向左滑动将其添加回去? - iOS 7 added slide to the right to pop a view controller off the stack. Is it possible to add it back by sliding left? 检测是否按下了后退按钮并等待用户操作弹出到上一个视图 - Detect if back button is pressed AND wait user action to pop to previous view 按下导航控制器后退按钮时如何导航到其他View Controller? - How to navigate to some other View Controller when Navigation Controller back button is pressed? 在检测到按下后退按钮后如何将数据发送回第一个视图控制器? - How can I send data back to the first view controller after detecting that the back button was pressed? 按下时,UIToolbar按钮会使应用程序崩溃 - UIToolbar button crashes app when pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM