ios - AppDelegate和.xib没有正确实现,但是构建成功了?

标签 ios xcode uitableview delegates xib

我真的不知道如何在不粘贴我所有代码的情况下解释这一点,但我会尝试一下。 “假设”我的 .hs 和 .ms 是准确的,我感觉我的 .xib 设置不正确,但我无法真正粘贴其中的代码。相反,我压缩了文件并上传了源代码。 (如果你足够勇敢,它就在这里:http://bit.ly/ZtDkGi)我得到了成功的构建,但我的模拟器的屏幕在应用程序启动后只是黑色的。

本质上,我必须手动添加一个 appDelegate 对象。我将类(class)设置为适当的类(class) - 但它仍然没有拉动。如果有人愿意提供帮助,那就太好了。

这是我的 Test_TableViewAppDelegate.h

#import <UIKit/UIKit.h>
@interface Test_TableViewAppDelegate : NSObject <UIApplicationDelegate>
{

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end

这是我的 Test_TableViewAppDelegate.m

#import“Test_TableViewAppDelegate.h”

@implementation Test_TableViewAppDelegate

@synthesize window=_window;
@synthesize navController=_navController;


- (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];

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor greenColor];
self.window = window;

UIViewController *fvc = [[UIViewController alloc] init];

UIViewController *rootController = [[UIViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];

//UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
self.navController = nc;

//[self.window addSubview: nc.view];
//[self.window makeKeyAndVisible];


self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {
NSMutableArray *petsArray;

}

@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

最后但并非最不重要的一点是,main.m(我认为这也可能是一个问题)

#import "Test_TableViewAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([Test_TableViewAppDelegate class]));
}
}

提前致谢。我将不胜感激:D

最佳答案

在您的委托(delegate)中Test_TableViewAppDelegate 为什么要向窗口添加两次 View ?

// you could remove these two lines
[self.window addSubview: nc.view];
[self.window makeKeyAndVisible];  

//keep these two lines
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];

您要添加到 navigationController 的此 View 未使用任何 Nib 名称进行初始化

UIViewController *fvc = [[UIViewController alloc] init];

在您的委托(delegate)中初始化应该像这样

RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];

关于ios - AppDelegate和.xib没有正确实现,但是构建成功了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15274515/

相关文章:

ios - swift 线程 1 : EXC_BAD_INSTRUCTION when I try to change a uilabel. 文本

ios - 如何在Azure DevOps中安装net6的iOS工作负载?

objective-c - 使用 OpenCV,如何在执行 OCR 之前检测文本方向?

xcode - Productbuild:将第三方产品存档添加到安装程序中?

ios - Xcode 不接受 72x72px 应用程序图标?

ios - 如何获取外围设备(BLE设备)和中央设备(iPhone)之间的连接间隔

iOS 6 旋转到 Portrait Upside Down 不适用于 UITableViewController,iOS 5 很好

iphone - 仅当内容不适合时才滚动 UITableView

ios - append 字典,iOS,Swift

iphone - 在通过 Segue 之前显示事件指示器