我有一个CoreData项目和2个实体,名称是MainList和Football ..
MainList实体有3个attriubutes;
LISTNAME; listFavoritePlayer listPlayerValue
足球实体有2个属性;
teamName; teamBestPlayerValue
我从AddFootball viewcontroller添加属性。喜欢;
addTeam.teamName = _txtTeamName.text;
addTeam.bestPlayerValue = _txtBestPlayer.text;
addMainList.listName = _txtListName.text;
addMainList.favoritePlayer = _txtFavoritePlayer.text;
addMainList.playerValue = _txtPlayerValue.text;
我从tableviewcontroller中获取了MainList。
cell.textlabel.text = mainList.listName;
cell.detailTextLabel.text = mainList.playerValue;
现在没关系。通过这种方式,我将团队属性保存到我的Football实体中,然后我可以在带有MainList的tableviewcontroller中显示它们。
但是......这里有一个问题;
当我想在我的Add FootballViewController中添加仅使用此代码的FavoritePlayer时。
addMainList.favoritePlayer = @"Messi";
MyTableView单元格为空。因为我没有添加mainList.listName和mainList.playerValue。但我想添加没有listName和playerValue的favoritePlayer,以便从另一个viewcontroller获取。
我想我需要一个if else声明或其他想法。
如果cell.textLabel.text = nil;不要显示
OR
如果选择了。 listName = nil;不要显示Cell。
OR
在显示Cell之前删除它们为空或nil。
我只想要除listName或playerValue之外的1个属性。
答案 0 :(得分:2)
单元格的显示应基于您事先确定的数据源。我将首先过滤数据源以删除不包含mainList.listName和mainList.playerValue的对象。然后......重新加载表格。