2013-05-22 23 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

這是一個很好的指導,但我認爲她正在尋找示例代碼。 –