我需要爲表格視圖添加一個搜索欄。表格包含實際存儲在名爲「患者」對象內部的「名稱」。我有一組「患者」對象。 所以要設置一個搜索欄來搜索名稱。但是如何使用NSPredicate來實現呢?用於表格視圖的搜索欄
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* CellId= @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellId] ;
}
cell.accessoryType = UITableViewCellAccessoryNone;
ObjPatient = [allPatientDetails objectAtIndex:indexPath.row];
cell.textLabel.text =[NSString stringWithFormat:@"%@ %@",ObjPatient.firstName,ObjPatient.lastName];
return cell;
}
以上是顯示錶格名稱的代碼。 歡迎任何建議,謝謝
http://www.appcoda.com/how-to-add-search-bar-uitableview/ –
謝謝,但我下面的一樣。問題是如何使用NSPredicate來「命名」哪個對象的屬性。我有一個這樣的對象數組。 –