【问题标题】:iphone simulator only loading black screeniphone模拟器只加载黑屏
【发布时间】:2014-02-16 04:53:30
【问题描述】:

我目前正在尝试在 Xcode5 中以表格视图列表的形式制作线路管理应用程序。我正在尝试将作为 queue.h 属性的 mutablearray 提供给也具有可变数组属性的 queueviewcontroller。这样做的主要原因是我稍后将创建另一个 nsmutablearray,其对象是队列的数组,即它将是成员列表的列表。 由于某种原因(我已经搜索过 Google 和 SO),应用程序编译得很好,即没有问题,但是当我运行模拟器时,它只会产生黑屏。

我在编程方面相对较新,因此不胜感激。如果你们需要更多信息,请告诉我。

Queue 是一个 NSObject 子类,具有一个名为 arrayQueue 的 NSMutableArray 属性

情节提要只是一个导航控制器,附带有 tableviewcontroller(QueueViewController)。

这是来自 QueueViewController.m 的代码 .h 文件只有一个名为 *queue 的 nsmutable 数组属性;

@implementation QueueViewController
{
Queue *list;
}

- (void)viewDidLoad
{
[super viewDidLoad];

list = [[Queue alloc]init];

QueueMember *member = [[QueueMember alloc]init];
member.name = @"adam";
member.rank = 1;
member.eta = 5;
[list.arrayQueue addObject:member];

member = [[QueueMember alloc]init];
member.name = @"bob";
member.rank = 2;
member.eta = 10;
[list.arrayQueue addObject:member];

member = [[QueueMember alloc]init];
member.name = @"cason";
member.rank = 3;
member.eta = 15;
[list.arrayQueue addObject:member];

QueueViewController *queueViewController = [[QueueViewController alloc]init];
queueViewController.queue = list.arrayQueue;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QueueCell"];

QueueMember *member = (self.queue)[indexPath.row];
cell.textLabel.text = member.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d min", member.eta];

return cell;
}

整个应用 delegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the  background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

【问题讨论】:

  • 我很欣赏快速响应。我有点困惑,因为我不认为我使用的是 MainWindow.xib 视图插座,因为这是 xcode5。另外,我不确定应用程序目标设置窗口中的主界面在哪里?其他答案与我的情况无关,因为这不是启动延迟的问题,而是它只是不启动
  • 你用这个 QueueViewController 做了什么?向我们展示这个视图控制器的代码
  • 感谢您的链接,我发布了上面的代码,我想知道我应该如何设置根视图控制器?我正在尝试添加以下代码,但我不确定将什么作为 initWithRootViewController 的参数? UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:rootView]; self.window.rootViewController = navController;

标签: ios objective-c ios-simulator rootview


【解决方案1】:

您没有设置windowrootViewController

编辑:

您可以在viewDidLoad 中创建数组。在viewDidLoad 写:

list = [[Queue alloc]init];

QueueMember *member = [[QueueMember alloc]init];
member.name = @"adam";
member.rank = 1;
member.eta = 5;
[list.arrayQueue addObject:member];

member = [[QueueMember alloc]init];
member.name = @"bob";
member.rank = 2;
member.eta = 10;
[list.arrayQueue addObject:member];

member = [[QueueMember alloc]init];
member.name = @"cason";
member.rank = 3;
member.eta = 15;
[list.arrayQueue addObject:member];

【讨论】:

  • 我以为我在这段代码中将 rootViewController 设置为 navigationController。故事板也有导航控制器作为初始视图,到目前为止它在其他应用程序上对我有用。你的意思是我应该在 uinavigationcontroller *navigationcontroller 上添加这样的东西吗?:
  • UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier: UINavigationController]; self.window.rootViewController = viewController
  • 我不确定如何实例化,因为故事板不是实际的类/类型。
  • 我将代码的末尾更改为此导致崩溃,因为“索引零超出了空数组的范围”。至少有人可以让我知道我的方向是否正确吗?
  • self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // 应用程序启动后自定义的覆盖点。 UINavigationController *viewController = [[UINavigationController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]; self.window.rootViewController = viewController; UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; QueueViewController *queueViewController = [navigationController viewControllers][0]; queueViewController.queue = list.arrayQueue;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-11
  • 1970-01-01
  • 2011-03-21
  • 2013-02-15
  • 2017-01-25
  • 1970-01-01
相关资源
最近更新 更多