【发布时间】:2014-05-28 14:50:39
【问题描述】:
这是我的表格视图的功能。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.categories count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"test";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d", self.collections.count);
return [self.collections count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
switch ([indexPath section])
{
case 0:
self.myList = self.collections;
break;
}
cell.textLabel.text = self.collections[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 48;
}
实际上,使用此代码,我的表格视图在同一视图中显示所有部分和单元格。
但是,我想要一个表格视图,它首先显示一行带有我的部分标题。 当我单击有我的部分标题的行时,我想显示该部分中的单元格。我怎样才能做到这一点? 我需要 2 个 tableViews 吗?
【问题讨论】:
-
所以你想制作一个可折叠的表格视图?好吧...在那种情况下,不你不需要需要 2
tableViews。您可以只需一点点努力就可以做到这一点,但请注意它完全依赖于数据源。您是如何构建数据源的?我的意思是它是字典数组还是什么? -
查看此链接:Expandable/Collapsable Accordion UITableView 大致了解您将进入的内容
-
我的数据源在 NSMutableArray 中。
-
我不想要手风琴。当我点击部分的标题时,我想要一个只有我的项目的新表格视图。
-
好的,所以在这种情况下,您仍然可以通过适当地更改数据源来使用单个
tableView。但首先...self.categories和self.collections中有什么?并且...您打算如何填充节标题(我假设来自self.categories)?请包含足够多的以下结果:[1]NSLog(@"%@",self.categories)和 [2]NSLog(@"%@",self.collections)以便更清楚地了解您拥有的内容
标签: ios uitableview cell sections