我如何使用NSPredicate和UISegmentedControl过滤UITableView

时间:2015-10-14 00:19:57

标签: objective-c uitableview nspredicate uisegmentedcontrol

我做的第一件事是将def show_frame(self): """ Animate the webcam on the video label :return: """ _, frame = self.cap.read() frame = cv2.flip(frame, 1) cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA) img = Image.fromarray(cv2image) imgtk = ImageTk.PhotoImage(image=img) self.webcam_label.imgtk = imgtk self.webcam_label.configure(image=imgtk) self.webcam_label.after(30, self.show_frame) 添加到我的.h文件中并在我的.m文件中合成它 然后我将以下代码链接到故事板上的我的段控制器以及我之前提到的IBOutlet

@property (strong, nonatomic) IBOutlet UISegmentedControl *statusControl;

我跑了调试,我在这里遇到了崩溃-(IBAction)indexChanged:(UISegmentedControl *)sender { switch (statusControl.selectedSegmentIndex) { case 0: selectedStatus = @"ALL"; NSLog(@"ALL"); break; case 1:{ selectedStatus = @"NEW"; NSPredicate *new= [NSPredicate predicateWithFormat:@"SELF.STATUS contains[c] NEW"]; listOfEstNetGrand = [[listOfEstNetGrand filteredArrayUsingPredicate:new] mutableCopy]; NSLog(@"NEW"); break; } case 2: { selectedStatus = @"COMPLETED"; NSPredicate *completed = [NSPredicate predicateWithFormat:@"SELF.STATUS contains[c] COMPLETED"]; listOfEstNetGrand = [[listOfEstNetGrand filteredArrayUsingPredicate:completed] mutableCopy]; NSLog(@"COMPLETED"); break; } } [self.tableView reloadData]; }

没有代码,我记录正确的NSLog所以我知道按钮工作,但我不能过滤我的uitableview。我做错了什么?

任何帮助将不胜感激。感谢

编辑:继续崩溃我得到了listOfEstNetGrand = [[listOfEstNetGrand filteredArrayUsingPredicate:new] mutableCopy];

编辑2:我将我的代码更改为*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CactusQueue 0x13ce87800> valueForUndefinedKey:]: this class is not key value coding-compliant for the key COMPLETED.'*** First throw call stack:并且有效。不确定为什么我在搜索时使用NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"STATUS contains[cd] COMPLETED"];

1 个答案:

答案 0 :(得分:0)

你的谓词应该像

NSPredicate *completed = [NSPredicate predicateWithFormat:@"SELF.STATUS contains[c] 'COMPLETED'"];

NSPredicate *completed = [NSPredicate predicateWithFormat:@"SELF.STATUS contains[c] %@",@"COMPLETED"];

请注意'您提供的价值'。否则谓词会将其视为对象的属性