我有一个sqlite3数据库的应用程序。在控制台中我可以看到应用程序可以从中读取数据,但是,我无法在屏幕上获取它。它只是一个白色的屏幕,我不知道为什么。有我的代码: AppDelegate文件:
#import <UIKit/UIKit.h>
@interface FailedBanksAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *_navController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end
和.m部分:
#import "FailedBanksAppDelegate.h"
#import "FailedBankDatabase.h"
#import "FailedBankInfo.h"
@implementation FailedBanksAppDelegate
@synthesize navController = _navController;
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSArray *failedBankInfos = [FailedBankDatabase database].failedBankInfos;
for (FailedBankInfo *info in failedBankInfos)
{
NSLog(@"%d: %@, %@, %@", info.uniqueId, info.name, info.city, info.state);
}
[self.window addSubview:_navController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
self.navController = nil;
}
@end
我遵循该教程http://www.raywenderlich.com/913/sqlite-101-for-iphone-developers-making-our-app,完成了作者所做的一切,但是,只是一个白色的屏幕,即使没有行!是的,我确实连接了网点..
在控制台中,我可以看到: 2012-03-18 11:15:56.186 Doctorina [3091:f803] 230:First Alliance Bank&amp;新罕布什尔州曼彻斯特的Trust Co. 2012-03-18 11:15:56.186 Doctorina [3091:f803] 231:伊利诺伊州大都市国家大都会 2012-03-18 11:15:56.187 Doctorina [3091:f803] 232:
在我写这篇文章之前,我在控制台中收到了消息 - 应用程序需要一个根视图控制器,然后我改变了self.window的窗口,消息消失了。还是白屏......
我添加了该代码,就像你说的那样:
UITableViewController *rootController = [[UITableViewController alloc] initWithNibName:@"FailedBanksListViewController" bundle:nil];
_navController = [[UINavigationController alloc] initWithRootViewController:rootController];
但现在它说 - 程序收到SIGABRT消息。
有我的FailedBanksListViewController文件:
.h文件是:
#import <UIKit/UIKit.h>
@interface FailedBanksListViewController : UITableViewController {
NSArray *_failedBankInfos;
}
@property (nonatomic, retain) NSArray *failedBankInfos;
@end
.m文件是:
#import "FailedBanksListViewController.h"
#import "FailedBankDatabase.h"
#import "FailedBankInfo.h"
@implementation FailedBanksListViewController
@synthesize failedBankInfos = _failedBankInfos;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.failedBankInfos = [FailedBankDatabase database].failedBankInfos;
self.title = @"Failed Banks";
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [_failedBankInfos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
// Set up the cell...
FailedBankInfo *info = [_failedBankInfos objectAtIndex:indexPath.row];
cell.textLabel.text = info.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@",
info.city, info.state];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
答案 0 :(得分:1)
您没有初始化导航控制器。
(...)
for (FailedBankInfo *info in failedBankInfos)
{
NSLog(@"%d: %@, %@, %@", info.uniqueId, info.name, info.city, info.state);
}
UIViewController *rootController = [[UIViewController alloc] initWithNibName:@"YourNibFile" bundle:nil];
_navController = [[UINavigationController alloc] initWithRootViewController:rootController];
[self.window addSubview:_navController.view];
(...)
答案 1 :(得分:0)
您正在初始化并分配导航控制器,直到该部分正确..但是您没有向导航控制器添加任何根视图控制器... 见下面的代码
//导航控制器的实例化 UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:self.viewControllerObj];
//Navigation controller is asssigned as RootView Controller
self.window.rootViewController=nav;
这就是确保你已正确分配和初始化viewControllerObj
然后在viewControlleObj类
中您可以使用以下语法轻松导航其他应用。 [self.navigationController pushViewController:vcObj1 animated:YES];
在vcObj1中你可以使用
返回上一个视图self.navigationController的POpViewCOtnroller方法。
您可能会想,如果我们必须在视图控制器中再次创建一个navigationcotnroller,以便推送另一个视图控制器......
没有self.navigationcotnroller意味着您在appdelegate上创建的navigationcontroller实例...