ios - Show only part of coreData array -
i've tableview should display objects of coredata-entity if 1 of entity-attribute equal string.
there's entity called buy , 1 of it's attribute string called position
and in code tableviewcontroller is:
@property (strong) nsmutablearray *buy; - (nsmanagedobjectcontext *)managedobjectcontext { nsmanagedobjectcontext *context = nil; id delegate = [[uiapplication sharedapplication] delegate]; if ([delegate performselector:@selector(managedobjectcontext)]) { context = [delegate managedobjectcontext]; } return context; } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext]; nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname:@"buy"]; self.buy= [[managedobjectcontext executefetchrequest:fetchrequest error:nil] mutablecopy]; [self.tableview reloaddata]; }
and try display objects of buy contain position string equal "a". don't how write if-condition.
thanks answers in advance.
do following :-
nsstring *str="a"; nspredicate *predicate=[nspredicate predicatewithformat:@"position == %@",str];
so, viewdidappear function becomes :-
- (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext]; nsstring *str="a"; nspredicate *predicate=[nspredicate predicatewithformat:@"position == %@",str]; nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname:@"buy"]; [fetchrequest setpredicate : predicate ]; self.buy= [[managedobjectcontext executefetchrequest:fetchrequest error:nil] mutablecopy]; [self.tableview reloaddata]; }
Comments
Post a Comment