快速的問題。我有一個按鈕放置在一個視圖控制器,並在另一個UITableView(它已經填充自定義單元格包含標題,說明等)。我希望我的用戶能夠按下按鈕,並讓UITableView顯示過濾結果。如何指定篩選現有UITableView的條件?
代碼看起來像什麼?我怎樣才能使這個按鈕過濾我的UITableView與指定的標準?
這裏的按鈕的viewcontroller.m文件中的代碼:
- (IBAction)buttonpressed:(UIButton *)sender {
NSLog(@"Button Pushed!");
}
這裏就是我的TableViewController.m文件看起來像:
- (int)numberOfSectionsInTableView: (UITableView *)tableview
{
return 1;
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
} else {
return [Strains count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strainTableIdentifier = @"StrainTableCell";
StrainTableCell *cell = (StrainTableCell *)[tableView dequeueReusableCellWithIdentifier:strainTableIdentifier];
if (cell == nil)
cell = [[StrainTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strainTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StrainTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.titleLabel.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"Title"];
cell.descriptionLabel.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"Description"];
cell.ratingLabel.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"Rating"];
NSLog(@"%@", searchResults);
} else {
cell.titleLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:@"Title"];
cell.descriptionLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:@"Description"];
cell.ratingLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:@"Rating"];
}
{
}
return cell;
}
你的表視圖控制器使用故事板? – shim