我已经浏览了本网站上的一些帖子,但没有找到我的确切问题,所以我正在寻找一些建议。我目前有一个带有TaskList实体的应用程序,我用它来支持我当前的TableView。我想基于实体的多个属性创建部分。例如,我有一个“isShared bool
属性和一个”已完成的“bool
属性,我想显示部分以分组”共享“项目,”未共享“项目和”已完成“项目。
这是瞬态属性可行的情况吗?我见过的大多数应用程序只适用于单个属性,所以我无法将自己的大脑包裹起来。
提前致谢。
答案 0 :(得分:0)
我脑子里有个主意,但这可能不是最好的解决方案。你能根据你的bool属性创建三个包含“isShared”,“notShared”和“completed”对象的数组吗?
然后在你的tableview单元格方法
-(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]
刷新表格视图。
答案 1 :(得分:0)
我会使用带数组的字典。我会在initView或TableViewController的viewDidLoad方法中填充字典。