- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是 iOS 编程的新手,遇到了一个问题。
做了什么:
我已经创建了 iOS 应用程序。最初它有 main.m、AppDelegate.h、AppDelegate.m 和一些其他通常创建的支持文件(不带代码)。
然后我手动创建了带有接口(interface)(LoginView.xib)的XIB文件,并手动添加了LoginViewController.h和LoginViewController.m来控制XIB。
向 LoginViewController.h 添加了 socket 。
毕竟我设置了文件的所有者类 (LoginViewController) 并在 XIB 和 LoginViewController.h 之间建立了连接。
问题描述:
我需要显示实例化登录 View Controller 并在应用程序启动时立即显示登录 View 。
我尝试了几次并阅读了十几个论坛主题,但没有办法。除了白色窗口背景外,没有显示任何内容。我该如何纠正?
引用代码:
LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController
{
IBOutlet UIView *_loginView;
IBOutlet UITextField *_tfLogin;
IBOutlet UITextField *_tfPassword;
IBOutlet UIButton *_btnLoginToSystem;
}
- (IBAction)attemptLogin:(id)sender;
@end
登录 View Controller .m
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)attemptLogin:(id)sender
{
}
@end
AppDelegate.h
#import <UIKit/UIKit.h>
#import "LoginViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) LoginViewController *loginViewController;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
[self.window.rootViewController presentModalViewController:self.loginViewController animated:NO];
[self.window makeKeyAndVisible];
return YES;
}
更新!!!伙计们,多亏了你们,我发现了另一个问题。在您确认我的代码(当然是在适当的版本之后)是正确的之后,我启动了模拟器并看到我的应用程序崩溃并出现以下异常:
NSInternalInconsistencyException with the reason [UIViewController _loadViewFromNibNamed:bundle:] loaded the ... nib but the view outlet was not set.
感谢 StackOverflow,我修复了它。 Loaded nib but the view outlet was not set - new to InterfaceBuilder
Josh Justice 对我提供的主题的评论的引述链接:
- Open the XIB file causing problems
- Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
- If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
- In the right-hand sidebar, click on the third tab--the one that looks a bit like a newspaper
- Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
- In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
- You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
- Save the xib and re-run
大概这些信息聚合成一个点,会帮助其他新人更快通过我走过的路。
最佳答案
在 application:didFinishLaunchingWithOptions: 方法中将 LoginViewController 设置为 Root View Controller 。
self.window.rootViewController = self.loginViewController;
删除这一行:
[self.window.rootViewController presentModalViewController:self.loginViewController animated:NO];
关于ios - 连接在一起 : AppDelegate, ViewController 和 XIB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396947/
我现在在另一个 ViewController 之上展示了一个几乎透明的 ViewController,但它禁用了与下面的 ViewController 的交互。这是我目前使用的代码: topContr
我有一个 View Controller ,其工具栏上有 3 个 UIButtons,可以打开一个新的 View Controller 作为弹出窗口。我在 Storyboard 中创建了 Segues
这个问题在这里已经有了答案: Delegates in swift? (15 个答案) 关闭 3 年前。 在我的场景中,我试图在关闭 View Controller 期间将值从 ViewContro
假设我有两个 viewController,AViewController 和 BViewController。 AViewController 嵌入在 NavigationController 中(
我有 3 个 View Controller A、B 和 C。 我在 vcA 上,我使用 推送 vcB [self.navigationController pushViewController:vc
我想知道如何在 VC3 和 VC1 之间传递数据。 我拥有的是 Root View (VC1)。然后你输入一个tableView,如果你选择一个项目,你将进入tableView2(VC3) - 类别
我在使用 Unwind Segue 时遇到问题。我有 3 个 ViewController,它们都在名为 ViewController.swift 的类下。我试图获取最后一个 ViewControll
我有一个应用程序,其左上角有一个汉堡菜单。按下时,菜单会以 90% 的不透明度淡入当前 ViewController,显示应用程序的主要导航选项。 我使用下面的代码从页面呈现 viewControll
我的问题是,当我呈现一个 UIViewController 时,呈现的 View 变黑了。 我有一个名为 mainViewController 的 UIViewController,它是我窗口的 Ro
例如,当我呈现UIActivityViewController或UIAlertController时,我仍然可以看到背景viewController,我不想在viewContollerA中嵌入view
我从second viewController进入了third viewController,但是我不想回到第二个viewController,我需要直接回到我的第一个viewController,我
我的应用程序是标签栏(+ 导航)应用程序。在 FirstViewController 中,我调用 onModalView。 -(void) onFilter { FilterViewControl
Photo Sharing 部分是我写的一个ViewController,当我按下正确的项目时,PhotoSharingViewController 会动画出现。 这是我的代码: PhotoShari
我正在尝试在另一个 View Controller 中使用 subview Controller 的应用程序。我有一个 VC,我正在实例化另一个 VC,并在外部 VC 内使用它自己的 xib。 我使用
我正在寻找有关包含 ViewController 的滚动的想法。我需要知道包含 View Controller 的位置。我已经尝试过 UIPageViewController 但我无法让滚动委托(de
我有一个带有嵌入式 NavigationController 的基本 ViewController 来提供工具栏。 ToolBar 有三个按钮,用于通过 segue 调用 ViewController
我的应用程序中的伙计们,我在应用程序委托(delegate)方法中有一些代码 application:didFinishLaunchingWithOptions:确定初始 View Controlle
我遇到了一个问题,我将对此进行描述,并且发现了一些类似的问题,但我认为与我的问题无关。 我有一个 UITabBarController,其中有 2 个用于 VC1 和 VC2 的选项卡。 VC1 转到
我的应用程序中有一个计时器。如果计时器达到 0,则用户将被带到失败页面。当这种情况发生时,之前的 ViewController 没有被关闭,导致更多的内存被占用。 如果出现失败页面,我希望关闭之前的
在问这个问题之前,我当然做了一些调查。我在 google 和 stackoverflow 上找到的链接或主题之一是: How do I load another view controller fro
我是一名优秀的程序员,十分优秀!