と を使用Core Data
してUITableViewController
います。、および(ブール値)category
の列を持つテーブルがあります。name
descript
is_active
次のような結果を取得したい
SELECT *
FROM CATEGORY
WHERE IS_ACTIVE = 1
フォームを介してこれをアクティブにしました。
私はこのコードを試しています-ビューでは、このロードセクションがあります
- (void)viewDidLoad
{
[super viewDidLoad];
IMSAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
context = [appDelegate managedObjectContext];
NSEntityDescription *category = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:category];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *srotDesc = [[NSArray alloc]initWithObjects:sort, nil];
[request setSortDescriptors:srotDesc];
NSError *error;
NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];
if (results == nil) {
//error handle here
}
[self setArr:results];
NSLog(@"there is category array");
[self.tableView reloadData];
[arr count];
}
そして、tableViewCellでは
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Category *category = [arr objectAtIndex:indexPath.row];
// Configure the cell...
cell.textLabel.text = [category name];
cell.detailTextLabel.text = [category descript];
return cell;
}
すべての名前と説明のように、すべてのレコードを表示しています。
is_active = 1 のレコードのみを表示したい。