我有一个包含 40 个对象的表格视图。在 UISegment(男性、女性和两者)中单击时,我必须按性别过滤它们。它似乎正在工作,但表格视图没有刷新。请任何帮助将不胜感激。
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"People";
[self loadall];
[[NSBundle mainBundle] loadNibNamed:@"FilterSortView" owner:self options:nil];
self.filterControl.selectedSegmentIndex = -1;
[self.filterControl addTarget:self action:@selector( changeSegge ) forControlEvents:UIControlEventValueChanged];
}
#
我的第二种按性别过滤的方法
- (void)changeSegge
{
NSEntityDescription *personEntity = [NSEntityDescription entityForName:@"Person"
inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:personEntity];
NSError *error = nil;
self.people = [self.managedObjectContext executeFetchRequest:request error:&error];
if (error)
{
[NSException raise:NSInternalInconsistencyException format:@"Could not fetch Core Data records: %@",error];
}
if(filterControl.selectedSegmentIndex == 0){
NSPredicate *predicatem =[NSPredicate predicateWithFormat:@"gender == %@", @"m" ];
request.predicate=predicatem;
[self.tableView reloadData];
[request release];
NSLog(@"button 1");
}
非常感谢。