小弟在编写复选列表(用tableview 的每一个 cell 装每一个选项)时遇到刷新问题,点击刷新后,被选中的文件若上传成功,则在列表中不再显示,但是上传成功后刷新列表,原本存在的被选中的cell(用image标识)中的image下移到另一个cell中了。求大神帮我解决这个问题!!!!
或者求大神提供一个“复选列表”带自动刷新的可行方法!求大神帮忙小弟度过这个紧急时刻!
小弟在编写复选列表(用tableview 的每一个 cell 装每一个选项)时遇到刷新问题,点击刷新后,被选中的文件若上传成功,则在列表中不再显示,但是上传成功后刷新列表,原本存在的被选中的cell(用image标识)中的image下移到另一个cell中了。求大神帮我解决这个问题!!!!
或者求大神提供一个“复选列表”带自动刷新的可行方法!求大神帮忙小弟度过这个紧急时刻!
好吧,最后我解决了这个问题,方案如下:
1.设置一个全局变量flag,当做刷新的标志位,
2.确定总共上传x个文件,把标志位置成x,每上传成功一次,标志位自减1;
3因为 tableview?.reloadData() 时,有多少个cell,便会调用多少次 tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell ,所以 每加载一个cell时都可判断一下 if(flag >=0){把cell的“button图片” —> “未选中button图片”,flag--;}else{flag = -1}
4.其余时候下的刷新(比如说下拉刷新)flag < 0, 并不会更新每个cell中button的图片。
5.如果我解释的不清楚,或者有什么更好的方式,请联系我!
部分代码如下:(有很多函数都是自己写的,看起来比较乱,请见谅 )
/*上传*/
func uploadClicked(){
prepareForUpload()
uploadAudioAndImage(uploadAudioID, ID : ID , insuranceID: insuranceID, idataIcard: idataIcard, userCode: userCode)
uploadVideo(uploadVideoID, ID : ID , insuranceID: insuranceID, idataIcard: idataIcard, userCode: userCode)
timer = NSTimer.scheduledTimerWithTimeInterval(1,
target:self,selector:Selector("tickDown"),
userInfo:nil,repeats:true)
upload.enabled = false
upload.setTitle("正在上传", forState: UIControlState.Normal)
coverView = UIView(frame: CGRectMake(0, 130, self.view.frame.size.width, self.view.frame.size.height))
coverView!.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
self.view!.addSubview(coverView!)
}
/*轮询是否上传完成*/
func tickDown(){
let defaults = NSUserDefaults.standardUserDefaults()
let temp = defaults.integerForKey("temp_done")
if(temp == 0){
upload.enabled = true
upload.setTitle("上传资料", forState: UIControlState.Normal)
coverView?.removeFromSuperview()
rfClick()
timer.invalidate()
}
}
/*上传完成后,刷新页面*/
func rfClick(){
audioID = searchAudioID(insuranceID)
videoID = searchVideoID(insuranceID)
//maintableview?.reloadData()
dispatch_async(dispatch_get_main_queue(), {
self.flag = self.audioID.count + self.videoID.count
self.maintableview?.reloadData()
})
}
//flag 为全局变量,常态时置成 -1(上传完成,flag置成 -1)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:(UITableViewCell) = UITableViewCell(style:.Default,reuseIdentifier:"Identifier") as UITableViewCell
if(indexPath.section==0){
let cell:audioCheckboxTableViewCell = maintableview!.dequeueReusableCellWithIdentifier("audioCheckboxTableViewCell", forIndexPath: indexPath) as! audioCheckboxTableViewCell
cell.audioName.text = (audioID[indexPath.row]["audio_id"]as? String)!
cell.tag = 0
if flag > 0
{
flag--
cell.butSelect.setImage(UIImage(named: "fx_02"), forState: UIControlState.Normal)
}else{flag = -1}
cell.textLabel!.font = UIFont.systemFontOfSize(14)
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
if(indexPath.section==1){
let cell:videoCheckboxTableViewCell = maintableview!.dequeueReusableCellWithIdentifier("videoCheckboxTableViewCell", forIndexPath: indexPath) as! videoCheckboxTableViewCell
cell.videoName.text = (videoID[indexPath.row]["VIDEO_ID"]as? String)!
cell.tag = 1
if flag > 0
{
flag--
cell.butSelect.setImage(UIImage(named: "fx_02"), forState: UIControlState.Normal)
}else{flag = -1}
//cell向右箭头
cell.accessoryType = UITableViewCellAccessoryType.None
cell.textLabel!.font = UIFont.systemFontOfSize(14)
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
//cell向右选择箭头
cell.accessoryType = UITableViewCellAccessoryType.None
cell.textLabel!.font = UIFont.systemFontOfSize(14)
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}