我有一个UITabBarController设置与2 UINavigationControllers.
一个UINavigationController有一个UIViewController,另一个UINavigationController有两个UIViewControllers.然后,如果您导航到第二个UIViewController并单击已选中的选项卡,它会将您带到UINavigationController的根目录(这将是第一个UIViewController).
有没有办法阻止这种情况发生?我不希望用户能够单击已选择的选项卡以转到导航控制器的根目录.
当用户点击按钮时,我使用以下代码显示上一个视图
[self.navigationController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
在上一个视图中,我覆盖了viewWillAppear来初始化一些东西.但是,似乎没有调用viewWillAppear.我把NSLog放在viewDidload,viewWillAppear,viewDidAppear中,只调用viewDidAppear.这是正常的行为吗?如果是,我应该覆盖什么事件,以便我可以进行初始化?谢谢.
按要求-viewWillAppear查看上一个视图
- (void)viewWillAppear:(BOOL)animated{
NSLog(@"ViewWillAppear");
//[[GameStore defaultStore] resetGame];
[self setHangmanImage];
NSLog([[[GameStore defaultStore] selectedList] label]);
[labelListName setText:[NSString stringWithFormat:@"List Name: %@", [[[GameStore defaultStore] selectedList] label]]];
[labelCurrentIndex setHidden:YES];
[labelCurrentWord setHidden:YES];
[[self navigationController] setNavigationBarHidden:NO];
[FlurryAnalytics logEvent:@"GameViewController - viewWillAppear"];
[self getNewQuestion];
NSLog(@"ViewWillAppear finish");
[super viewWillAppear:YES];
}
Run Code Online (Sandbox Code Playgroud)
我使用以下代码在app委托中设置UINavigationalController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
HomeViewController *hv = [[HomeViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:hv];
// You can now release the itemsViewController here,
// UINavigationController will retain it
[hv release];
// Place …Run Code Online (Sandbox Code Playgroud) 这可能听起来像一个新手问题,但我是iOS开发新手.
我在navigationController中推送了一个视图,假设它是第3个推送视图.在那个视图中我设定了self.navigationController.delegate = self;.我已经更改了委托,因为我需要处理用户转到上一个视图的情况,即从当前视图弹出.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([[viewController class] isEqual:[MainViewController class]]) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但当我弹出当前视图并再次按导航后退按钮(即切换到第一个推送视图)时,我的访问错误.
那么我错过了什么?处理导航后退按钮的正确方法是什么?
我有两个TableViewControllers,中间有一个segue.当用户点击第一个TVC中的小区时,他们将看到第二个TVC.segue是模态的,有一个名为"segueToLocationDetails"的标识符,并传递一个对象.您或多或少可以将第二个TVC视为"详细信息"页面.
我的代码在我上面描述的场景中完美运行.然而,只要我将第二个TVC嵌入导航控制器,它就会中断.
例.我有完美的工作.然后我突出显示IB中的第二个TVC,将鼠标移到Product | 嵌入| 导航控制器.现在第二个TVC在导航控制器中.然而,segue仍然指向第二个TVC.我删除了segue并将其从第一个TVC的单元重新连接到导航控制器,并确保给segue一个标识符.再次跑,它打破了!错误低于......
2011-12-23 15:30:45.469 Project12 [5219:11603] - [UINavigationController setDetailsObject:]:无法识别的选择器发送到实例0x7b92ce0 2011-12-23 15:30:45.471 Project12 [5219:11603] *终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是: ' - [UINavigationController的setDetailsObject:]:无法识别的选择发送到实例0x7b92ce0'*第一掷调用堆栈:(0x16ea052 0x150ad0a 0x16ebced 0x1650f00 0x1650ce2 0x3933 0x703e1e 0x36f6d9 0x36f952 0xbf786d 0x16be966 0x16be407 0x16217c0 0x1620db4 0x1620ccb 0x14ec879 0x14ec93e 0x2dfa9b 0x2a98 0x29f5 0x1)终止调用抛出异常当前语言:auto; 目前客观的c
下面的一些代码可以帮助解释:
AllLocations.h和AllLocations.m(这是主表)
AllLocations.h
@interface AllLocations : UITableViewController
{
SQLiteDB *mySQLiteDB;
}
@property (nonatomic, strong) NSMutableArray *locationsArray;
AllLocations.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"segueToLocationDetails" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueToLocationDetails"])
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试简单的操作.至少看起来很简单.好吧,我想做的是从一个用模态视图控制器推动的视图中推送视图(使用推视图控制器).
View1 - (使用模态视图控制器推送) - > View2 - (使用推视图控制器推送) - View3.
Rigth现在,我正在做测试,所以我正在使用一个按钮来启动动作.这是我用来从View2推送到视图3的代码:
//view2.h
UIToolbar *bar;
UIBarButtonItem *button;
UIToolbar *toolbar;
}
- (IBAction)demissModal:(id)sender;
- (IBAction)goView3:(id)sender;
@end
//view2.m
- (IBAction)goView3:(id)sender{
View3 *view_3 = [[View3 alloc] initWithNibName:@"View3" bundle:nil];
[self.navigationController pushViewController:view_3 animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这是我用来将View1推送到View2的相同代码,它可以工作.但是当将View2推送到View3时,它无法正常工作.知道为什么会这样吗?谢谢!
我一直处理这个(有点)随机的bug一段时间,无法弄清楚问题.上下文:我正在创建一个UISplitView iPad应用程序,在主视图中有一个UINavigationController:
主菜单为红色,子菜单为绿色,主要内容为紫色.
这个UINavigationController没有填满整个Master视图,因为我需要一些空间来拥有一个垂直菜单.当用户选择垂直侧菜单上的按钮时,它会为UINavigationController设置一些新内容,以显示带有选项的UITableView.我在每个菜单选择上做的是:
[self.subMenu setViewControllers:@[subMenuViewController] animated:YES];
Run Code Online (Sandbox Code Playgroud)
发生的事情是我不需要保留菜单历史记录,所以我每次都要为subMenu设置一个新的根视图控制器.
问题是当我开始搞乱设备方向时.它没有清晰的图案,但有时,在旋转时,我的应用程序崩溃了.现在,当我使用Instruments运行它时,这就是我得到的:
167 Zombie -1 00:32.101.527 UIKit -[UITableView _spacingForExtraSeparators]
Run Code Online (Sandbox Code Playgroud)
有趣的是,糟糕的访问发生在subMenu的前一个根视图控制器上.因此,如果我点击"事件"然后点击"播客",则在尝试访问"EventsViewController"时会发生错误访问.
所以我猜测在替换subMenu UINavigationController的根视图控制器的方式上有些不对,但我不确定它是什么.也许我需要确保在设置新的根视图控制器之前释放当前的根视图控制器?
任何帮助深表感谢.:)
因此,假设您需要一些需要下一个故事板的功能.例如,您需要根据单击的选项卡上载不同的内容以进行查看.

但是当你尝试使用这个故事板时问题出现了.当您切换标签时,您会收到此行为.

但在第一个选项卡一切都很好.所以看起来它没有第二次加载视图.在这种情况下,有人可以解释或给出导航控制器行为的链接,因为我在参考中找不到任何有用的东西.或者我应该如何在IB中或以编程方式更正此行为?
谢谢.
我有一个嵌入在UINavigationController中的UITableViewController,我正在尝试将Peek&Pop实现到TableView中.我有"偷看"部分完美地工作,但当我尝试"弹出"到下一个ViewController时,我正在"偷看"的单元格和下一个单元格都显示出来.我正在"弹出"到UICollectionView中,正如我所提到的,"peek"一半显示正确的单元格,但"pop"却没有.这个问题只发生在我使用[self.navigationController showViewController:viewControllerToCommit sender:nil];或[self.navigationController pushViewController:viewControllerToCommit animated:YES];执行"pop"时.
我尝试使用[self presentViewController:viewControllerToCommit animated:YES completion:nil];并显示正确的单元格,除了这不会给我我需要的导航元素,所以我不能使用它(除非有办法让所有的导航元素回来).
我最初的想法是,我的应用程序如何计算CollectionViewCell的大小有问题.这是我正在使用的代码,虽然看起来它可以正常使用Peek&Pop以外的所有内容.
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize collectionViewBounds = collectionView.bounds.size;
int navigationHeight = self.navigationController.navigationBar.bounds.size.height;
int toolbarHeight = self.navigationController.toolbar.bounds.size.height;
int statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
int cellHeight = collectionViewBounds.height - (navigationHeight + statusBarHeight + toolbarHeight);
int cellWidth = collectionViewBounds.width;
return CGSizeMake(cellWidth, cellHeight);
}
Run Code Online (Sandbox Code Playgroud)
为了增加我的困惑,当"TableView"中的第一个或最后一个项目被"偷看"时,"pop"将完美地运行.任何有关这方面的帮助将不胜感激.
iphone objective-c uinavigationcontroller uicollectionview 3dtouch
有关设置手势识别器的样板文件以及交互式过渡,请参阅此答案.
我正在尝试交互式过渡,并花了相当多的时间试图弄清楚为什么控制器会正常转换而不是根据手势擦洗.我发现它没有用,因为我正在使用UIViewPropertyAnimator.切换到较旧的UIView动画块开箱即用.为什么?实施有什么区别?
func animateTransition(using transitionContext: UIViewControllerContextTransitioning)
{
// Ignore the forced unwrapping, for sake of brevity.
let view_From = transitionContext.viewController(forKey: .from)!.view!
let view_To = transitionContext.viewController(forKey: .to)!.view!
transitionContext.containerView.insertSubview(view_To, aboveSubview: view_From)
view_To.alpha = 0
// This animation block works - it will follow the progress value of the interaction controller
UIView.animate(withDuration: 1, animations: {
view_From.alpha = 0.0
view_To.alpha = 1.0
}, completion: { finished in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
// This animation block fails - it will play out normally …Run Code Online (Sandbox Code Playgroud) uiview uinavigationcontroller ios swift uiviewpropertyanimator
我的viewcontroller有一个tableview,我可以在不同的部分填充我的视图.我正在尝试向此tableview添加刷新控件.我实施的内容如下.
func setUpRefreshControl() {
let refreshControl = UIRefreshControl()
refreshControl.tintColor = UIColor.red
refreshControl.addTarget(self, action: #selector(handleRefresh(_: )), for: UIControlEvents.valueChanged)
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}
}
@objc func handleRefresh(_ sender: UIRefreshControl) {
print("-----------REFRESHED------------")
}
Run Code Online (Sandbox Code Playgroud)
接下来,当我下拉tableview进行刷新时,刷新控件(设置为红色)可见.但是,不调用目标函数.
我的viewcontroller位于标签栏控制器内,该控制器嵌入在导航控制器中.我想这个问题与视图层次结构有关,因为当我在没有导航栏和标签栏的单独项目中尝试相同的代码时,它的工作正常.但我无法弄清楚当前的问题是什么.解决这个问题的任何建议?谢谢.
编辑:我在不同的模拟器中测试它:6,6s,6s +,7,7 +,8,8 +,X.我发现上面的代码在包括X在内的所有加号版本中运行良好.但是,所有模拟器都在运行ios 11.2所以我仍然无法弄清楚可能导致这个问题的原因.
uitabbarcontroller uinavigationcontroller tableview uirefreshcontrol swift