類後:http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/的UITableView空,甚至稱這裏按照本教程的reloadData
我用的提取記錄方法在我AppNameDelegate.m文件。然後我調用我的tableview重新加載。與鏈接教程不同,我沒有使用UITableViewController。相反,我爲NavigationController添加了一個表視圖,並將它連接到名爲contactsTable的IBOutlet變量。
這裏是我的代碼調用並加載數據:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:[self.navigationController view]];
[self fetchRecords];
[self.contactsTable reloadData];
[self.window makeKeyAndVisible];
}
頭文件:
//
// SimpleContactsAppDelegate.h
// SimpleContacts
//
// Created by Aaron McLeod on 11-05-28.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface SimpleContactsAppDelegate : NSObject <UIApplicationDelegate> {
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
UIWindow *window;
UINavigationController *navigationController;
// view for adding new contacts
UIViewController *newContactView;
UIButton *addButton;
// controls for the addContactView
UIButton *saveContactButton;
UITextField *nameField;
UITextField *emailField;
UITextField *phoneField;
UITableView *contactsTable;
NSMutableArray *contactArray;
}
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIButton *addButton;
@property (nonatomic, retain) IBOutlet UITableView *contactsTable;
@property (nonatomic, retain) NSMutableArray *contactArray;
// controller and fields for the form
@property (nonatomic, retain) IBOutlet UIViewController *newContactView;
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *emailField;
@property (nonatomic, retain) IBOutlet UITextField *phoneField;
@property (nonatomic, retain) IBOutlet UIButton *saveContactButton;
- (NSString *)applicationDocumentsDirectory;
- (IBAction) saveContact;
- (IBAction) switchToAddContactView;
- (void)fetchRecords;
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
@end
你可以在這裏找到我的項目的源代碼,以及:https://github.com/agmcleod/SimpleContacts/tree/parttwo如果我離開了代碼你可能需要。謝謝。
我甚至不確定它爲什麼這麼低。我的問題11/13都已經接受了答案。 – agmcleod 2011-05-30 11:15:03