Iphone 设备上的空白屏幕;模拟器工作正常
我正在编写一个带有导航控制器的iOS应用程序。当我在模拟器上打开它时,它运行良好。当我在设备上运行它时,状态栏下方会显示一个空白屏幕。另外,我无法确定我的RootViewController在哪里被设置为默认视图(我怀疑这是我的问题的根源) RootViewController.mIphone 设备上的空白屏幕;模拟器工作正常,iphone,ios,Iphone,Ios,我正在编写一个带有导航控制器的iOS应用程序。当我在模拟器上打开它时,它运行良好。当我在设备上运行它时,状态栏下方会显示一个空白屏幕。另外,我无法确定我的RootViewController在哪里被设置为默认视图(我怀疑这是我的问题的根源) RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Main Menu"; } 无视图将显示、视图显示等 显示包含0个元素的表 - (
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Main Menu";
}
无视图将显示、视图显示等
显示包含0个元素的表
- (UITableViewCell *)tableView:(UITableView *)tv
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
tv.backgroundColor = [UIColor whiteColor];
UITableViewCell *cell;
if (indexPath.row == 0)
cell = newsCell;
else if (indexPath.row == 1)
cell = configureCell;
else if (indexPath.row == 2)
cell = aboutCell;
return cell;
}
- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section
{
return 0;
}
#pragma mark UITableViewDelegate Methods
- (CGFloat)tableView:(UITableView *)tv
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 84;
}
- (void) tableView:(UITableView *)tv
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (0 == indexPath.row)
{
}
else if (1 == indexPath.row)
{
}
else if (2 == indexPath.row)
{
}
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
[tableView release];
[newsCell release];
[configureCell release];
[aboutCell release];
}
RootViewController.h
@interface RootViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView;
IBOutlet UIView *displaySplashScreen;
IBOutlet UITableViewCell *newsCell, *configureCell, *aboutCell;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@接口RootViewController:UIViewController
{
UITableView*表格视图;
IBUIView*显示屏幕;
IBOutlet UITableViewCell*新闻单元格,*配置单元格,*关于单元格;
}
@属性(非原子,保留)IBUITableView*tableView;
这里有几个问题。首先,您的AppDelegate标头应为:
@class RootViewController;
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
彭尼的回答是正确的,除非我做一点小改动。这样做:
#import "RootViewController.h"
@implementation MyAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
rootViewcontroller = [[RootViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
这是显示导航控制器的更好方式。正如PengOne所说,这一定是Interface Builder文件的问题。解开所有物件,然后再次将其连接起来,以查看问题是否仍然存在。如果是,请检查以确保所有内容都正确命名。祝你好运 谢谢。这清理了我的代码,对此我非常感激。但是,它并没有清除我的设备上显示的黑屏,上面只有一个状态栏。具体来说,将显示viewDidLoad和(如果适用)viewDidLoad。问题可能就在那里。对原来的帖子进行了修改。他们可能会有所帮助。请尝试
self.navigationItem.title=@“主菜单”
。为了好玩,还可以尝试更改背景颜色(self.view.backgroundColor=[UIColor redColor];
),看看会发生什么。我的猜测是IB中的东西没有正确连接。self.navigationItem.title=@“主菜单”不会创建任何更改,self.view.backgroundColor=[UIColor redColor];不创建任何更改。也就是说,在模拟器中,一切看起来都正常(不是红色),但设备有一个带有白色状态栏的黑屏。我的所有链接在Interface builder中都是一致的。aboutCell、configureCell和newsCell链接到表视图单元格。视图链接到视图。“表视图”链接到“表视图”。表视图的数据源和委托链接到文件的所有者。这是正确的,不是吗?好的,我重建了IB文件(RootViewController和MainWindow),但没有成功。我看不出IB怎么会导致设备专有的问题,而不是模拟器的问题。无论如何,我只是从头开始重建了整个项目,现在所有的东西都可以在模拟器和设备上运行。没有学到什么,但它是有效的。奇怪的是,一定是非常罕见的事情。有时,“清理”项目(产品>清理)将有助于解决类似的问题。对不起,它让你头疼,但我很高兴它现在能用了。
@class RootViewController;
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
#import "RootViewController.h"
@implementation MyAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
rootViewController = [[RootViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:rootViewController];
[window addSubview:[navController view]];
[self.window makeKeyAndVisible];
return YES;
}
#import "RootViewController.h"
@implementation MyAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
rootViewcontroller = [[RootViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}