2011-05-04 60 views
0

我有一个带有搜索栏(搜索显示控制器)的表格视图我需要组织结果的部分...在开始时有1个部分和搜索结果,他们可以有1或2或3节...你有一个很好的方法来做到这一点?在UITableView中组织搜索控制器的结果

谢谢!

+0

这可能有助于某人http://stackoverflow.com/a/39388169/2033377 – 2016-09-08 10:39:56

回答

0

取决于您如何捕获您的搜索结果。

通常你会想要NSArray的NSMutableArray。这样,你的主要array.count就成为你的部分数量,并且行数将成为该indexpath上的嵌套数组的数量。 NSDictionaries数组也是典型的。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return [mainArray count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [[mainArray objectAtIndex:section] count]; 

}