首页 \ 问答 \ iOS使用UINavigationController滑出菜单(iOS Slide out menu with UINavigationController)

iOS使用UINavigationController滑出菜单(iOS Slide out menu with UINavigationController)

我正在尝试编写一个使用主视图控制器(VC)和三个子视图的滑出菜单。 如果我想要的话,我希望子视图能够成为UINavigationControllers ...但是我将它们添加为主VC的子项时遇到了麻烦。

主视图是中心视图的代表。

似乎正在发生的事情是导航栏被赋予主vc而不是由孩子保留(如果这有意义)。 见图:

在此处输入图像描述

我最近下载了另一个产生所需效果的库(CHSliderMenu),它在iOS6 / 7中运行得很好,但是我无法区分作者正在做什么和我正在做什么之间的区别。 我知道我很接近,这就是让人难以理解的原因:(

以下是我的MainViewController中尝试添加子nav控制器的代码:

self.view.frame = self.view.bounds;

_centerViewController = [[D2CenterViewController alloc] init];
_centerViewController.view.backgroundColor = [UIColor whiteColor];
_centerViewController.view.tag = CENTER_TAG;
_centerViewController.delegate = self;

UINavigationController *centerNavController = [[UINavigationController alloc] initWithRootViewController:_centerViewController];

[self addChildViewController:centerNavController];
[self.view addSubview:centerNavController.view];

你能看出我可能出错的地方吗? 诊断需要更多代码吗?


I'm trying to write a slide out menu that uses a main viewcontroller(VC) and three subviews. I want the subviews to be able to be UINavigationControllers if I want...but I'm having trouble adding them as children of the main VC.

The main view is the delegate of the center view.

What seems to be happening is that the nav bar is being given to the main vc and not retained by the child (if that makes any sense). See Image:

enter image description here

I've recently downloaded another library that yields the desired effect (CHSliderMenu) and it works just fine in iOS6/7, but I'm unable to distinguish the difference between what the author is doing and what I'm doing. I know I'm close, which is what's making this so hard to figure out :(

Here is the code in my MainViewController that attempts to add the child nav controller:

self.view.frame = self.view.bounds;

_centerViewController = [[D2CenterViewController alloc] init];
_centerViewController.view.backgroundColor = [UIColor whiteColor];
_centerViewController.view.tag = CENTER_TAG;
_centerViewController.delegate = self;

UINavigationController *centerNavController = [[UINavigationController alloc] initWithRootViewController:_centerViewController];

[self addChildViewController:centerNavController];
[self.view addSubview:centerNavController.view];

Can you see where I may have gone wrong? Is more code needed to diagnose?


原文:https://stackoverflow.com/questions/17160393
更新时间:2022-11-13 12:11

最满意答案

您正在创建NSURL的字符串是普通的NSString 。 要在NSString使用变量,您可以使用:

[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];

%@是字符串的占位符。 variable1variable2必须是NSString

创建的行可能如下所示:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2]];

要么:

NSString * urlString = [NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];
NSURL * url = [NSURL URLWithString:urlString];

The string you are creating the NSURL with is a normal NSString. To use variables in a NSString, you can use:

[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];

%@ is a placeholder for a string. variable1 and variable2 must be NSStrings

The line that creates could look like this:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2]];

Or:

NSString * urlString = [NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];
NSURL * url = [NSURL URLWithString:urlString];

相关问答

更多
  • 您正在使用同步API,因此当方法返回时,连接已经完成。 如果您使用异步API,您可以使用任何+connectionWithRequest:delegate: ,- –initWithRequest:delegate:或–initWithRequest:delegate:startImmediately: 。 You're using the synchronous API, so when the method returns the connection has already finished. You ...
  • 您正在创建NSURL的字符串是普通的NSString 。 要在NSString使用变量,您可以使用: [NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2]; %@是字符串的占位符。 variable1和variable2必须是NSString 创建的行可能如下所示: NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"ht ...
  • 尝试 center: markers.latitude + ',' + markers.longitude, Try center: markers.latitude + ',' + markers.longitude,
  • 你的比较; if(niks == @"null") 仅比较指针是否相等(即两者是否是相同的字符串对象实例)。 由于一个是常量而另一个是从服务器获取的JSON动态创建的,因此它不太可能。 要比较两个字符串的内容 ,你应该做; if([niks isEqualToString:@"null"]) 对于链接口渴, 这里是[NSString isEqualToString:]文档 。 Your comparison; if(niks == @"null") only compares if the point ...
  • 有没有办法像在C ++中一样在声明中使用非指针版本的对象? XCode似乎不想让我。 NSObject类型不支持此功能。 Clang不支持创建自己的root objc类(如果你足够怪异的话,你可以用GCC来做)。 因此,简短的回答是“不,你不能按值声明NSObject类型”。 但这并不重要; 正确的解决方案是弄清楚你的成员被清除的原因 - 使用引用计数指针适用于其他所有人。 Is there a way to have a non pointer version of an object in the de ...
  • 您已启用延迟扩展,但您没有使用它。 为了使用延迟扩展,你需要使用!variable! 而不是%variable% 。 此外, for循环中指定的变量区分大小写,因此您需要将var1设置为等于%%A或使用%%a作为循环变量。 setlocal enabledelayedexpansion for /f %%i in ("Report.txt") do set size=%%~zi if %size% gtr 0 ( for /F "tokens=1-4 delims=," %%a in (Rep ...
  • a,b,c = "1 2.2 -3.14".split.map(&:to_f) # => [1.0, 2.2, -3.14] b # => 2.2 a,b,c = "1 2.2 -3.14".split.map(&:to_f) # => [1.0, 2.2, -3.14] b # => 2.2
  • NSDictionary *whatToPost= [NSDictionary dictionaryWithObjectsAndKeys: username, @"username", password, @"password", nil]; NSString *url = [NSString stringWithFormat:@"http://domain.com/user/get?data=%@", [whatToPost JSONString]]; NSURL *theUrl = [NSUR ...
  • 您错过了URL中的方案( https://或http:// )。 因此请求将失败。 此外,您应该直接使用URLWithString : NSString *urllink = [NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?lat=%f&lon=%f&appid=%@", lat, lng, WEATHERAPIKEY]; NSURL *jsonURL = [NSURL URLWithString:ur ...
  • 您可以简单地为配置对象实现__getattr__()函数 def __getattr__(self, name): if name in self.items: return self.items[name] else: raise AttributeError() 有关python文档中__getattr__()的说明,请参见此处 。 You could simply implement the __getattr__() function for y ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。