是否可以在弹出窗口内的UIViewController中显示工具栏项?我在我的视图控制器的viewDidLoad方法中这样做:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
[self setToolbarItems:[NSArray arrayWithObject:addButton]];
[addButton release];
Run Code Online (Sandbox Code Playgroud)
然后我将这个视图控制器包装在一个UINavigationController(它有一个toolbar属性,根据文档,我应该使用setToolbarItems方法UIViewController向项目工具栏添加项目),然后在弹出窗口中呈现它.
我没有看到工具栏.使用弹出窗口时是否不支持工具栏?
谢谢
cocoa-touch uitoolbar uiviewcontroller uinavigationcontroller ipad
我正在尝试使用一些分层视图实现导航控制器.我想使用常规的UIViewController来呈现向下钻取的选项,我不想使用导航栏 - 我想拥有自己的自定义按钮来返回一个级别.
我看到如下例子:
[[self navigationController] pushViewController:nextViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
我的问题是这些:是navigationController所有UIViewControllers的属性吗?self.navigationController无论堆栈中的视图如何,我都可以参考吗?如果我处于任意视图中,我是否可以使用包含类似内容的按钮操作[self.navigationController popToRootViewController animated:YES];
我提供的每个视图都需要一个按钮来返回上一个视图或根视图,具体取决于具体情况.我想在每个视图控制器中创建该按钮,并控制它返回的堆栈中的哪个视图.我是在正确的轨道上吗?
当我显示时ABPersonViewController,我需要一个按钮,允许我将其关闭并返回上一个屏幕.我该如何添加?
如何从代码中简单地在UINavigationController中查看一个视图?
这么简单..谢谢,克里斯蒂安斯图尔特
好的,所以这实际上已经解决了 - 但我不明白为什么我的工作.
我的问题是发送一次通知会导致一次事件多次触发.我最终在堆栈上看到了几个不需要的视图.简而言之:
用户按下工具栏中的按钮,从代理发送通知
mapItem = [[UIBarButtonItem alloc] initWithImage:mapImage style: UIBarButtonItemStylePlain target:self action:@selector(mapButtonPressed:)];
-(void)mapButtonPressed:(id)sender{
NSLog(@"Map Button Pressed");
[[NSNotificationCenter defaultCenter] postNotificationName:@"mapButtonPressed" object:nil ] ;
}
Run Code Online (Sandbox Code Playgroud)
这会在当前视图中触发一个函数,将地图视图推送到堆栈上.
-(void)openListMap:(NSNotification *)aNotification {
mapViewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
NSLog(@"Map Created");
mapViewController.searchLocation = searchLocation;
if(givenLocationType == @"input"){
mapViewController.inputLocationText = inputLocationText;
}
mapViewController.givenLocationType = givenLocationType;
CultureNOWAppDelegate *delegate =
[[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:mapViewController
animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
现在,我改变了最后一行:
CultureNOWAppDelegate *delegate =
[[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:mapViewController
animated:YES];
Run Code Online (Sandbox Code Playgroud)
至:
[self.navigationController pushViewController:mapViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
结果是,尽管openListMap函数仍然会多次触发(您可以在控制台中看到,自应用程序启动以来每次出现视图时,日志输出显示"Map Created")它只将最新的mapView推送到堆栈.
但为什么?为什么它首先会多次触发,为什么它会通过交换两段代码而停止,这些代码对于所有意图和目的都是相同的?
谢谢你的任何想法.
我试图在UINavigationController层次结构中添加splitview作为子页面.我猜这是可能的,但不确定.否则,我将只需手动执行类似的功能.
cocoa-touch uinavigationcontroller ipad uisplitviewcontroller
我有2个视图共享相同的类文件(.h和.m).在第一个视图中,我有一个UIPicker,其中包含一个项目列表和一个按钮.如果用户单击该按钮,我希望我的第二个视图提供相应的图片(基于在UIPicker中选择的项目).
我的想法是根据所选项目在第一个视图中设置NSString.然后,当用户单击按钮将第二个视图推送到屏幕上时,我可以使用新视图传递该字符串.我一直在"谷歌搜索"一段时间,但我似乎无法用手指环绕它.如果重要,我正在使用导航控制器.这是在按钮单击上执行的代码:
-(IBAction) viewPictures{
ViewControllerClass *sView = [[ViewControllerClass alloc] initWithNibName:@"ViewController2XIB" bundle:nil];
[self.navigationController pushViewController:sView animated:YES];
}
Run Code Online (Sandbox Code Playgroud) 我一直在通过我的应用程序试图处理所有的内存问题和阅读内存管理.我开始使用[object retainCount]来跟踪我的内存分配.这是否值得信任,因为我一直觉得这些计数真的很奇怪?
有人可以解释以下内容:
请记住,这个app委托和一个空的mainViewController没有任何区别.initWithRootViewController导致计数上升,但我没有看到添加一个的另一种方法....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/* Create the View Controllers */
UIViewController *mainViewControl = [[[MainViewController alloc] init] autorelease];
/* Create the Navigation Controller */
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:mainViewControl] autorelease];
NSLog(@"retain count: %i",[mainViewControl retainCount]);
/* Set the toolbar to purple */
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
navigationController.navigationBar.tintColor = [UIColor colorWithRed:.6 green:.1 blue:.4 alpha:0.4];
navigationController.navigationBar.translucent = YES;
NSLog(@"retain count: %i",[mainViewControl retainCount]);
navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
navigationController.toolbar.tintColor = [UIColor colorWithRed:.6 green:.1 blue:.4 alpha:0.4];
navigationController.toolbar.translucent = YES;
[navigationController setNavigationBarHidden:YES animated:NO]; …Run Code Online (Sandbox Code Playgroud) apple提供的默认NavigationController模板,它有一个navigationController和一个表.
如果选择一个单元格,新视图将被推送到navigationController中,如果弹出视图,所选单元格将自动取消高亮显示.
但是表如何知道何时去高亮它以及它如何知道选择了哪个单元?
或者它只是重新加载所有数据?
我需要通过调用我已经拥有的方法来保存我的数据,当使用UINavigationController创建的后退按钮弹出viewController时.
有没有办法获得委托回调或通知我没有在文档中看到任何内容?
iphone ×5
ios ×3
cocoa-touch ×2
ipad ×2
nsstring ×1
objective-c ×1
retaincount ×1
sdk ×1
uitableview ×1
uitoolbar ×1
variables ×1