2013-05-22 19 views
0

快速的问题。我有一个按钮放置在一个视图控制器,并在另一个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; 

} 
+0

你的表视图控制器使用故事板? – shim

回答

0

在创建表视图控制器按钮按下的方法(如果你使用故事板,那么你会连接到第二个视图控制器的按钮,然后在prepareForSegue中做到这一点,否则只是创造e按钮内的视图控制器实例按下并将其推送到导航控制器)。

属性或实例变量添加到指定要应用和设置,当你创建表视图控制器,然后执行滤波viewDidLoad中和/或的cellForRowAtIndexPath过滤

+1

这是一个很好的指导,但我认为她正在寻找示例代码。 –