Код для моего UITableView
не краснеет, что может только meen мой массив не заселен. Я использую core-database
, и, как я вижу из печати, я получаю, что это показывает, что у моей БД есть данные. Он просто не отображается. Вот мой код:NSMutableArray не заселен
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:nil];
[self reloadArray];
}
-(void) reloadArray
{
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
NSManagedObjectContext *context = [delegate managedObjectContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:context];
[fetch setEntity:entity];
NSManagedObject *object = nil;
NSError *error;
NSArray *result = [context executeFetchRequest:fetch error:&error];
for (int i = 0; i < [result count]; i ++) {
object = [result objectAtIndex:i];
[_projectArray addObject:[object valueForKey:@"name"]];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
[self reloadArray];
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_projectArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"TableCell";
NSManagedObject *object = [self.projectArray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
tableView.delegate = self;
tableView.dataSource = self;
cell.textLabel.text = [_projectArray objectAtIndex: indexPath.row];
return cell;
}
Прежде всего установите точку останова после выполнения запроса на выборку и проверьте, что говорит об ошибке. – user2260054
Зачем вам нужно [self reloadArray]; в numberOfSectionsInTableView? – user2260054
При настройке точки останова она показывает, что Error = nil, и она показывает, что в таблице видны 4 строки, 4 элемента в Entity @ «Project» и 4 элемента в массиве. –