在我的应用程序中,我为视图添加了一个标签,将其连接到插座,但是当我第一次从另一个视图控制器分配此插座然后调用pushViewController以显示它时,没有显示任何内容.这是推送显示标签的下一个视图之前的代码:
CustomViewController *vc = [[CustomViewController alloc] init];
vc.lbl_price.text = self.label_price.text; // lbl_price is defined as a property in CustomViewController and label_price is defined in current view controller
[self.navigationController pushViewController:vc];
Run Code Online (Sandbox Code Playgroud)
在CustomViewController viewDidLoad方法中,我添加了这条指令,看它是否应该有效
NSLog(@"Price=%@",lbl_price); // it actually prints out what was previously assigned
Run Code Online (Sandbox Code Playgroud)
但它并没有显示在标签上!
知道为什么吗?
斯特凡
我显然错过了一些东西......
在我的iOS应用程序中,我将UIViewController推送到导航控制器:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:@"MyViewController"];
[self.navigationController mvc animated:YES];
Run Code Online (Sandbox Code Playgroud)
MyViewController显示正常,我可以看到并使用navigationBar,但当我尝试从视图控制器中获取指针返回导航控制器时,我得到一个零结果.
UINavigationController *nav = [self navigationController];
if (!nav) {
NSLog(@"no nav");
}
Run Code Online (Sandbox Code Playgroud)
我整天都在反对这一点,但却看不出我做错了什么.我在Xcode中没有任何警告或错误.我完全错过了什么吗?
TIA:约翰
我有一个选项卡式应用程序,其中包含选项卡中的导航控制器和视图控制器.所有这些都使用相同的导航控制器导航栏:后退按钮+徽标图像.目前,我将此代码放在每个视图控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Back";
UIImage *headerImage = [UIImage imageNamed:@"Logo.png"];
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:headerImage] autorelease];
}
Run Code Online (Sandbox Code Playgroud)
恕我直言,这不是最好的方法.我正在考虑使用UIViewController的类别并覆盖viewDidLoad方法,但是每个视图控制器都有一些额外的代码要在viewDidLoad中执行,所以我猜覆盖不是解决方案.还有什么其他方法?
如何UINavigationController在按下按钮时显示提示?我已经设置了我的文字[[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt is working!"]];
编辑:为了澄清,我有一个按钮调用一个IBAction设置提示如下,但我需要找到一种方法,一旦按下该按钮显示提示:
-(IBAction)test:(id)sender
{
[[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt works!"]];
//I want it to display right after I set it, so I'm missing something and can't figure it out through the documentation
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试[[[self navigationController]navigationBar]pushNavigationItem:nav animated:YES];但是会引发错误说明Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.
我很长一段时间一直是这个网站的忠实粉丝,但这是我发布的第一个问题.
我已经阅读了与主题相似的每个帖子(我认为),但他们都使用NIB文件. 我的项目中的任何地方都没有nib文件.
这是一个带有一个视图的简单项目(这意味着一个委托类,一个uiviewcontroller类和一个uiview类),我的视图显示正常,除了从未调用viewDidLoad方法.
main.m看起来像这样:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"MyAppDelegate");
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
MyAppDelegate.m看起来像这样:
-(void)applicationDidFinishLaunching:(UIApplication *)application{
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = localWindow;
[localWindow release];
MainViewController *viewController = [[MainViewController alloc] init];
//Option 1
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
////Option 2
//navigationController = [[UINavigationController alloc] init];
//navigationController.viewControllers = [NSArray arrayWithObject:viewController];
////Option 3
//navigationController = [[UINavigationController alloc] init];
//[navigationController pushViewController:viewController animated:NO]; …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码在导航控制器中创建工具栏:
[self.navigationController setToolbarHidden:NO];
//Create a button
NSArray *toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStyleBordered target:self action:@selector(helpButton:)]
,nil];
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,只要有导航控制器(多个其他视图),工具栏就可见.有没有办法只将工具栏限制在一个视图?
谢谢
我如何在标签栏应用程序中"打洞",基于标签栏的应用程序可以显示每个标签中的uinavigationcontrolner背后的视图?(可以选择关闭此打孔).
我的代码,即应用程序委托,用于创建选项卡是:
OneRootViewController *oneRootViewController = [[OneRootViewController alloc] initWithNibName:@"OneRootViewController" bundle:nil];
UINavigationController *oneNav = [[UINavigationController alloc] initWithRootViewController:oneRootViewController];
oneNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"One" image:[UIImage imageNamed:@"one.png"] tag:0];
TwoRootViewController *twoRootViewController = [[TwoRootViewController alloc] initWithNibName:@"TwoRootViewController" bundle:nil];
UINavigationController *twoNav = [[UINavigationController alloc] initWithRootViewController:twoRootViewController];
twoNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Two" image:[UIImage imageNamed:@"two.png"] tag:1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:oneNav, twoNav, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
这是我喜欢它的工作方式:
-----------------------------
| |
| --------------- |
| | | |
| | hole which | |
| | shows …Run Code Online (Sandbox Code Playgroud) 我有问题让我的导航控制器正常运行!如果我在RootViewController中单击表格的单元格,它似乎不是下一个ViewController.
错误消息读取
"应用程序试图将nil视图控制器推向目标."
所以我分配了一些错误的东西,我的猜测,我可能遗漏了我所遵循的书中的重要内容.
所以问题出现在我的RootViewController.m中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UINavigationController *navigationController= [[UINavigationController alloc]init];
switch ([indexPath row]) {
case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate.m中,我正在做以下事情来将RootViewController设置为NavigationController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Navigation Controller
RootViewController *rootViewController = [[RootViewController alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible]; …Run Code Online (Sandbox Code Playgroud) 有没有办法可以在我的应用程序中独立使用这些分页点,
将它们添加到我的UIView/NIB并调用它上面的函数来设置总点数或当前页面/点.
基本上我在一个nib文件中有UIViewImage,我在滑动手势上显示图像(从数组中取出的名称),并希望在底部显示这些寻呼点以获取导航信息.
iphone uiscrollview uinavigationcontroller uipagecontrol ios
我有以下问题:我已经覆盖popViewControllerAnimated:(BOOL)animated了UINavigationController因为我想要一个自定义动画.代码如下:
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
UIViewController *poppedCtrl = [super popViewControllerAnimated:NO];
[((customViewController *) self.topViewController) doCustomAnimation];
return poppedCtrl;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,UINavigationBar似乎忽略了我明确禁用内置动画并且它仍然是动画的.
我还需要做些什么才能阻止导航栏的动画?