我在这个网站上搜索了一些帖子,但没有找到我的确切问题,所以我正在寻找一些建议。我目前有一个带有 TaskList 实体的应用程序,我用它来支持我当前的 TableView。我想根据实体的多个属性创建部分。例如,我有一个“isShared”bool
属性和一个“已完成”bool
属性,我想显示部分以对“共享”项目、“未共享”项目和“已完成”项目进行分组。
这是瞬态属性可以工作的情况吗?我见过的大多数应用程序只适用于单个属性,所以我无法围绕它展开我的大脑。
提前致谢。
我在这个网站上搜索了一些帖子,但没有找到我的确切问题,所以我正在寻找一些建议。我目前有一个带有 TaskList 实体的应用程序,我用它来支持我当前的 TableView。我想根据实体的多个属性创建部分。例如,我有一个“isShared”bool
属性和一个“已完成”bool
属性,我想显示部分以对“共享”项目、“未共享”项目和“已完成”项目进行分组。
这是瞬态属性可以工作的情况吗?我见过的大多数应用程序只适用于单个属性,所以我无法围绕它展开我的大脑。
提前致谢。
我有一个想法,但这可能不是最好的解决方案。你能根据你的布尔属性创建三个包含“isShared”、“notShared”和“completed”对象的数组吗?
然后在您的表格视图单元格方法中
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Custom your cell for different section here
switch (indexPath.section)
{
//First section is shared item
case 0:
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//Custom your cell here, for example, you can assign an item in your list to the cell's textlable
cell.textLabel.text = [sharedArray objectAtIndex:[indexPath row]];
}
break;
case 1:
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//Custom your cell for not shared item here
cell.textLabel.text = [notSharedArray objectAtIndex:[indexPath row]];
}
break;
case 2:
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//Custom your cell for not shared item here
cell.textLabel.text = [CompletedArray objectAtIndex:[indexPath row]];
}
break;
default:
break;
}
return cell;
}
因此,您会在表视图中获得三个按 bool 属性分组的部分。如果您更改列表中的一项,即从未共享部分共享一个未共享项,那么您可能需要实现一种方法将该对象从 unSharedArray 移动到 sharedArray,然后调用
[tableView reloadData]
刷新表视图。
我会使用带有数组的字典。我会在 TableViewController 的 init 或 viewDidLoad 方法中填充字典。