【发布时间】:2017-09-20 15:51:14
【问题描述】:
我正在开发一个公民参与应用程序,其中将包含一个 UITableView,列出所有 50 个州和华盛顿特区的选民登记信息。我编译了一个如下的 [[String]] 数组作为数据源:
[stateAbbv.,stateName,infoLink,onlineRegistrationLink]
示例:
["MO","Missouri","https://www.sos.mo.gov/elections/govotemissouri/register","https://s1.sos.mo.gov/votemissouri/request"]
["SD","South Dakota","https://sdsos.gov/elections-voting/voting/register-to-vote/default.aspx","nil"]
为了使 UITableView 更易于填充,我在 viewDidLoad 中将数组分解为 4 个单独的数组,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
print(voterInformation.count)
for items in voterInformation
{
stateAbbreviations.append(items[0])
stateNames.append(items[1])
voteInfoLinks.append(items[2])
onlineLink.append(items[3])
}
resultsTable.delegate=self
resultsTable.dataSource=self
在我的 tableView 单元格方法中,我对其进行了编码,以便如果在线注册链接不存在,“在线注册”按钮将被隐藏。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let newCell=resultsTable.dequeueReusableCell(withIdentifier: "stateRegistrationCell", for: indexPath) as! VoterRegistraionCell
print(indexPath.row)
newCell.stateName.text=stateNames[indexPath.row]
//print(voterInformation[indexPath.row][3])
if(voteInfoLinks[indexPath.row] == "No Voter Registration")
{
newCell.infoLink.setTitle("No Voter Registration", for: UIControlState.normal)
newCell.onlineRegistration.isHidden=true
}
else
{
newCell.infoLink.tag=indexPath.row
//print(voterInformation[indexPath.row][3])
if(onlineLink[indexPath.row] != "nil")
{newCell.onlineRegistration.tag=indexPath.row}
else
{
newCell.onlineRegistration.isHidden=true
}
}
return newCell
}
我的问题是,当我在模拟器中进行测试时,链接最初显示正常,但当我向下滚动时,一些本应存在的“在线注册”链接不存在。当我向上滚动时,以前存在的在线链接不再存在。 (例如阿拉巴马州)。关于为什么这些数据似乎会丢失有什么想法吗?
【问题讨论】:
标签: ios iphone swift uitableview