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:
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
最满意答案
您正在创建
NSURL
的字符串是普通的NSString
。 要在NSString
使用变量,您可以使用:[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];
%@
是字符串的占位符。variable1
和variable2
必须是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 normalNSString
. To use variables in aNSString
, you can use:[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];
%@
is a placeholder for a string.variable1
andvariable2
must beNSString
sThe 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根据变量设置(NSURL set from variables)[2022-02-03]
您正在创建NSURL的字符串是普通的NSString 。 要在NSString使用变量,您可以使用: [NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2]; %@是字符串的占位符。 variable1和variable2必须是NSString 创建的行可能如下所示: NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"ht ... -
如何使用变量设置选项?(How to set options using variables?)[2023-12-13]
尝试 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 ...
-
指针NSURL数据成员(pointer NSURL data member)[2021-08-14]
有没有办法像在C ++中一样在声明中使用非指针版本的对象? XCode似乎不想让我。 NSObject类型不支持此功能。 Clang不支持创建自己的root objc类(如果你足够怪异的话,你可以用GCC来做)。 因此,简短的回答是“不,你不能按值声明NSObject类型”。 但这并不重要; 正确的解决方案是弄清楚你的成员被清除的原因 - 使用引用计数指针适用于其他所有人。 Is there a way to have a non pointer version of an object in the de ... -
为什么没有设置变量(Why variables are not set)[2022-02-22]
您已启用延迟扩展,但您没有使用它。 为了使用延迟扩展,你需要使用!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
-
将JSON数据放入NSURL(Put JSON data in NSURL)[2021-12-03]
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 ...