- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我还是 iOS 编程的新手,尽管进行了大量研究,但我还是遇到了另一个障碍。
我要实现的:
我想要一个在我从主 UI 导航时加载的 UITabBarController。我还想使用 NIB 来定义它的属性。
我能找到的所有示例都将 UITabBarController 放在 AppDelegate 中,但我不想加载它,除非它被使用。我也不知道如果我只是模态地执行它,是否所有的 UIGestureRecognizers 都会保持事件状态(我无法获得有效的实现)。
到目前为止我有什么
首先,我从 AppDelegate 加载一个初始加载 View
AppDelegate.h
@class InitialViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
从这个角度来看,因为我只是制作 UI 的框架,所以我有两个按钮,一个转到主界面,另一个转到 UITabBarController。
InitialViewController.h
@interface InitialViewController : UIViewController
- (IBAction)toMain:(id)sender;
- (IBAction)toTabs:(id)sender;
@property (strong, nonatomic) UIViewController *mviewController;
@property (strong, nonatomic) UIViewController *tviewController;
@end
InitialViewController.m
- (IBAction)toMain:(id)sender {
self.mviewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[[[UIApplication sharedApplication] delegate] window].rootViewController = self.mviewController;
}
- (IBAction)toTabs:(id)sender {
self.tviewController = [[tabViewController alloc] initWithNibName:@"tabViewController" bundle:nil];
[[[UIApplication sharedApplication] delegate] window].rootViewController = self.tviewController;
}
在加载 MainViewController 时,它的行为与我想要的完全一样。但是当我加载选项卡 View 时,我会在底部看到一个长选项卡和黑色背景。我可以在 viewdidload 中添加内容,例如更改背景颜色,但没有实际的选项卡或 View 链接到 XIB 中的选项卡。
我怀疑我在两个方面缺少某些东西:在选项卡 .h 中,以及在界面生成器中与此相关联的一些链接。或者设置一个新的 rootViewController 是不够的。
tabBarController.h
#import <UIKit/UIKit.h>
@interface iPodViewController : UITabBarController <UITabBarControllerDelegate>
@end
如果有人能为我指出正确的方向和/或向我展示一个可行的实现方案,我将不胜感激。
-- 请注意,当我进入 tabbar.xib 并使用辅助编辑器时,它会打开 InitialViewController.h --
最佳答案
与其他 View Controller (例如 UITableViewController)不同,您不应该继承 UITabViewController。因此,与您其他的 View Controller 不同,您不进行子类化,然后让您的子类成为 nib 的所有者,指向 nib 中的 View ,具有自定义 View 。
相反,对于您想拥有 UITabBarController 的任何类,添加一个普通的普通 UITabBarController 作为此类的导出属性。 (例如,您的应用委托(delegate))。
然后创建一个nib文件,将一个UITabBarController对象拖入nib中。将 nib 的所有者设置为您想要拥有标签栏 Controller 的类(例如,您的应用委托(delegate)),并将您作为属性创建的导出连接到 nib 中的标签栏 Controller 。
@interface myTabOwningClass
@property (strong, nonatomic) IBOutlet UITabBarController myTabBarControllerOutlet;
现在,在您要创建和显示标签栏 Controller 的位置,使用以下方法:
[[NSBundle mainBundle] loadNibNamed:@"MyTabControllerNib" owner:myTabOwningClass options:nil];
这将初始化所属类的属性(即我们示例中的 myTabBarControllerOutlet),并从 nib 加载选项卡栏 Controller ,包括您在 nib 中定义的每个选项卡的所有 subview Controller 等。
关于xcode - 在 AppDelegate 之外使用 NIB 创建 UITabBarController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8978488/
我正在尝试在手写笔中使用 Nib CSS3 扩展。安装了手写笔和 Nib (尝试了本地和全局 -g)。但没有一个工作,当我做 stylus styles.styl > build/styles.css
我们当前的best-practice for custom views是: 在 Nib 中构建自定义 View 。 在 View Controller 中,以编程方式加载 Nib,从加载的对象数组中获
我是界面构建器的新手,我想要一个包含 UIView 的 3x3 网格的屏幕,每个网格都包含一个 UIImageView 和 4 个 UILabels。 我的逻辑可能有缺陷,但我试图实现这一目标的方式是
我有一个用 Swift 编写的框架/模块,它提供了一些具有 IBDesignable 功能的自定义控件。 目前我正在开发一个基于 CollectionView 的控件。 CollectionView
我有两个 nib 文件 - Main.nib 和 Preference.nib在 Main.nib 文件中,我有一个 NSView 类的实例。它的窗口有一个NSPopUpButton,单击它会显示一个
我想创建一个节标题来加载一个 nib 文件并将其设置为标题 UIView。这个 nib 文件还将有一个关联的类,其中连接了 outlets 和 action,所以我想像平常一样用 nib 加载那个类。
我正在尝试使用来自 this pre-built page menu pod from github 在说明中,它说: var controller : UIViewController =
我是 Cocoa 新手,无法将我的 nib 文件拆分为多个 nib 文件。 我的MainMenu.nib包含一个Tracker Controller对象,它是NSObject的子类。它在我的主菜单中有
我通过 XIB 创建了 CustomViewController。 我还通过作为 UIView 子类的不同 XIB 文件创建了 CustomView。 然后我将 UIView 绑定(bind)到 Cu
我正在使用自定义 UITableViewCell。当我尝试运行我的代码时,我得到了这个异常堆栈,我无法理解问题的根源: terminating app due to uncaught exceptio
我有两个 Nib ParentViewController.xib ChildViewController.xib ParentViewController.xib 包含一个 UIView 和一个 U
我一开始使用了一些 NSWindows 项目,但我的 GUI 正在不断发展,这些元素将更适合作为 NSViews。有没有办法将 NSWindow NIB 转换为 NSView NIB? 最佳答案 不存
我想要具有正确顺序的 View Controller 生命周期功能的完整列表。请任何天才。 请指定ViewController生命周期函数. 请指定序列号,例如用法:,并且仅使用简短描述。示例: 与使
我有两个 Nib :Parent.xib 和 Child.xib。 我已将子 Nib 包含在父 Nib 内以简化绑定(bind)。我在 loadView 中以编程方式设置 subview 。问题是,a
我正在开发一款通用应用程序,iPhone 版本运行良好。我为 iPad 创建了一个新的 nib,并将文件所有者设置为 viewcontroller 类。我连接了所有的 IBOutlets 和 IBAc
我有两个 UIViews,我将它们称为 A 和 B。 A 是B 的容器,每一个都是使用Interface Builder 创建的。 我需要使用界面生成器将我的 B View 添加到 A 中,如下图所示
谁能解释什么时候对同一个 NIB 文件使用多个 View 比使用多个 NIB 文件更好? 一个 NIB 文件可以包含多个 View ,因此有时使用一种方法比使用另一种方法更好。 我是不是太含糊了? 最
简单的任务:我有一个带有 2 个 NIB 文件的应用程序(每个 NIB 文件都有自己的 Controller )。我已经成功地显示了第二个 NIB 文件的窗口,就像我想要的那样,但现在,我想单击 NI
目前,我有一个托管上下文、许多相互关联的实体 NSArrayController,以及几个 Windows,每个 Windows 都使用 1 或 2 个 NSArrayController。 Wind
尝试创建一个 tableView 单元格 xib,但遇到错误“加载了 nib 但未设置 View 导出” 我读过很多帖子,大多数人都说将“ View ”从文件所有者拖到 IB View 。 但是,如果
我是一名优秀的程序员,十分优秀!