獲取我新的編程和iOS我想提出類似的CRUD操作和庫存系統的iPhone應用程序我不能夠顯示數據,並在UITableView的的UITableView不能夠顯示數據,而不是從陣列
獲取數據但當打印數組時,則產生這種類型的輸出。
2013-10-03 15:45:04.228 inventrymanagementsystem[1968:c07] name: (
"<Category: 0x7453f40> (entity: Category; id: 0x744a3b0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p1> ; data: <fault>)",
"<Category: 0x7456500> (entity: Category; id: 0x74501f0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p2> ; data: <fault>)",
"<Category: 0x7456210> (entity: Category; id: 0x7450970 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p3> ; data: <fault>)",
"<Category: 0x7457830> (entity: Category; id: 0x743bd90 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p4> ; data: <fault>)",
"<Category: 0x7455cf0> (entity: Category; id: 0x7438670 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p5> ; data: <fault>)",
"<Category: 0x744b060> (entity: Category; id: 0x7438530 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p6> ; data: <fault>)",
"<Category: 0x74496f0> (entity: Category; id: 0x7436050 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p7> ; data: <fault>)",
"<Category: 0x744f290> (entity: Category; id: 0x744db90 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p8> ; data: <fault>)",
"<Category: 0x744eaa0> (entity: Category; id: 0x7439d40 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p9> ; data: <fault>)",
"<Category: 0x744fec0> (entity: Category; id: 0x74385c0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p10> ; data: <fault>)",
"<Category: 0x744f410> (entity: Category; id: 0x7445de0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p11> ; data: <fault>)",
"<Category: 0x74557c0> (entity: Category; id: 0x744ebe0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p12> ; data: <fault>)",
"<Category: 0x7456190> (entity: Category; id: 0x7450b30 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p13> ; data: <fault>)",
"<Category: 0x7457010> (entity: Category; id: 0x7453180 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p14> ; data: <fault>)",
"<Category: 0x744b740> (entity: Category; id: 0x74524b0 <x-coredata://431EF8C4-5AAE-4AA8-ADFB-A09CE5731E2D/Category/p15> ; data: <fault>)"
)
我不明白是什麼問題。
代碼
#import "IMScategoriesViewController.h"
#import "IMSAddCategoryViewController.h"
#import "IMSAppDelegate.h"
#import "Category.h"
@interface IMScategoriesViewController()
@property (strong) NSMutableArray *categories;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property (nonatomic,retain) NSFetchedResultsController *fetchedresultcontroller;
@end
@implementation IMScategoriesViewController
- (NSManagedObjectContext *)managedObjectContext
{
NSManagedObjectContext *context;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
//- (void)viewDidAppear:(BOOL)animated
//{
// [super viewDidAppear:animated];
- (void)viewDidLoad
{
[super viewDidLoad];
// Fetch the devices from persistent data store
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Category"];
self.categories = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSLog(@"name: %@",self.categories);
[self.tableView reloadData];
// IMSAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
// self.managedObjectContext = appDelegate.managedObjectContext;
//
// // Fetching Records and saving it in "fetchedRecordsArray" object
// self.categories = [[appDelegate getallcategories]mutableCopy];
// NSLog(@"name: %@",self.categories);
// [self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.getallcategories count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// UITableViewCell *cell = [UITableView dequeueReusableCellWithIdentifier:@"Cell"];
//add this
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
Category * category = [self.getallcategories objectAtIndex:indexPath.row];
cell.textLabel.text = [category name];
return cell;
}
多少行顯示了視圖加載時?在你的'cellForRowAtIndexPath'方法中,當你把NSLog(@「這個類別是:%@」,category)時會發生什麼;'' – iwasrobbed
順便說一句,你應該使用'NSFetchedResultsController'而不是獲取整個'Categories'集合,因爲它只提取需要在屏幕上顯示的內容。 – iwasrobbed
Put'NSLog(@「This category is:%@」,category);'的,這是在節目輸出2013年10月4日08:31:16.062名:( 「<類別:0x845c8d0>(實體:類別; ID:0x845b720;數據:) 「 」<類別:0x845cb80>(實體:類別; ID:0x845b730 ;數據:)「, 」(entity:Category; id:0x845b740 ; data:)「, –