如何在uitableview swift 3中为特定索引添加数据
我正在CellforRowat中为特殊索引(即indexpath.row=0)创建一个动态uilabel 但当我向下滚动时,我也看到了第四个索引上的UI标签 如果我已经在Cellforroat中添加了一个条件,为什么会出现在第三个索引中:如何在uitableview swift 3中为特定索引添加数据,uitableview,swift3,Uitableview,Swift3,我正在CellforRowat中为特殊索引(即indexpath.row=0)创建一个动态uilabel 但当我向下滚动时,我也看到了第四个索引上的UI标签 如果我已经在Cellforroat中添加了一个条件,为什么会出现在第三个索引中: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // var cell:ActivityMainT
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// var cell:ActivityMainTableViewCell?
if(CheckFlag == false){
//CheckFlag = true
}
else{
CheckFlag = false
}
// cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! as? ActivityMainTableViewCell
let cell:ActivityMainTableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! ActivityMainTableViewCell
/// let cell = tableView.cellForRow(at: indexPath) as! ActivityMainTableViewCell
///let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ActivityMainTableViewCell
/// cell.viewheight.constant = 0
cell.imgViewFirst.layer.cornerRadius = (cell.imgViewFirst.frame.size.width) / 2
cell.imgViewFirst.layer.borderWidth = 3.0
cell.imgViewFirst.layer.borderColor = UIColor.white.cgColor
cell.imgViewFirst.clipsToBounds = true
cell.ImageViewThird.layer.cornerRadius = (cell.ImageViewThird.frame.size.width) / 2
cell.ImageViewThird.layer.borderWidth = 3.0
cell.ImageViewThird.layer.borderColor = UIColor.white.cgColor
cell.ImageViewThird.clipsToBounds = true
cell.ImageViewSecond.layer.cornerRadius = (cell.ImageViewSecond.frame.size.width) / 2
cell.ImageViewSecond.layer.borderWidth = 3.0
cell.ImageViewSecond.layer.borderColor = UIColor.white.cgColor
cell.ImageViewSecond.clipsToBounds = true
print(indexPath)
print(indexPath.row)
print(dicArray)
cell.DateOfMeeting.text = dicArray[indexPath.row]["Date"] as? String
cell.CompanyInMeetiong.text = dicArray[indexPath.row]["Company"] as? String
cell.lblNews.text = dicArray[indexPath.row]["News"] as? String
cell.lblCommonKey.text = dicArray[indexPath.row]["CommonKey"] as? String
print(SectordicArray)
cell.imgViewFirst.isHidden = true
cell.lblCommonKey.isHidden = true
cell.btnOthers.tag = indexPath.row
//for i in 0..<section.count {
print(cell.lblCommonKey.text)
print(indexPath.row)
RowHeight = 110.0
CellHeight = 140.0
isFirstTime = true
// print(AllCompanydicArray)
if(indexPath.row == 0){
let Data = AllCompanydicArray[indexPath.row]
print(Data)
for i in 0..<Data.count {
print(Data[i])
if(isFirstTime == false){
RowHeight = RowHeight + 30.0
CellHeight = CellHeight + 30.0
}
else{
isFirstTime = false
}
let Company = (Data[i] as NSDictionary).value(forKey: "Company") as! [String]
let Contacts = (Data[i] as NSDictionary).value(forKey: "Participants") as! [String]
// section.append(Company)
//items.append(Contacts)
for k in 0..<Company.count {
let newLabel = UILabel(frame: CGRect(x: 10.0, y: RowHeight, width:cell.frame.width, height: 30.0))
newLabel.text = Company[k]
newLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 13)
cell.addSubview(newLabel)
}
for j in 0..<Contacts.count {
RowHeight = RowHeight + 30.0
CellHeight = CellHeight + 30.0
var
newLabel = UILabel(frame: CGRect(x: 10.0, y: RowHeight, width:30, height: 30.0))
newLabel.text = CaptionName(Name: Contacts[j])
//"RC"
newLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 11)
newLabel.textAlignment = .center
newLabel.backgroundColor = getColorByHex(rgbHexValue: 0x002366, alpha: 0.9)// UIColor(red: 0.0, green: 14.0, blue: 40.0, alpha: 100.0)
newLabel.layer.cornerRadius = (newLabel.frame.size.width) / 2
newLabel.layer.borderWidth = 1.0
newLabel.clipsToBounds = true
newLabel.textColor = UIColor.white
newLabel.layer.borderColor = UIColor.white.cgColor
cell.addSubview(newLabel)
newLabel = UILabel(frame: CGRect(x: 50, y: RowHeight, width:cell.frame.width-30, height: 30.0))
newLabel.text = Contacts[j]//"Raghav Chopra"
newLabel.font = UIFont(name:"HelveticaNeue", size: 12)
cell.addSubview(newLabel)
}
}
}
else{
}
return cell
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
//变量单元格:ActivityMainTableViewCell?
if(CheckFlag==false){
//CheckFlag=true
}
否则{
CheckFlag=false
}
//cell=tableView.dequeueReusableCell(标识符为“cell”)!as?ActivityMainTableViewCell
将单元格:ActivityMainTableViewCell=tableView.dequeueReusableCell(标识符为“cell”)设为!ActivityMainTableViewCell
///将cell=tableView.cellForRow(at:indexPath)设为!ActivityMainTableViewCell
///让cell=tableView.dequeueReusableCell(标识符为“cell”,for:indexPath)作为!ActivityMainTableViewCell
///cell.viewheight.constant=0
cell.imgViewFirst.layer.cornerRadius=(cell.imgViewFirst.frame.size.width)/2
cell.imgViewFirst.layer.borderWidth=3.0
cell.imgViewFirst.layer.borderColor=UIColor.white.cgColor
cell.imgViewFirst.clipsToBounds=true
cell.ImageViewThird.layer.cornerRadius=(cell.ImageViewThird.frame.size.width)/2
cell.ImageViewThird.layer.borderWidth=3.0
cell.ImageViewThird.layer.borderColor=UIColor.white.cgColor
cell.ImageViewThird.clipsToBounds=true
cell.ImageViewSecond.layer.cornerRadius=(cell.ImageViewSecond.frame.size.width)/2
cell.ImageViewSecond.layer.borderWidth=3.0
cell.ImageViewSecond.layer.borderColor=UIColor.white.cgColor
cell.ImageViewSecond.clipsToBounds=true
打印(indexath)
打印(indexPath.row)
印刷品(迪加里)
cell.DateOfMeeting.text=dicArray[indexPath.row][“Date”]as?字符串
cell.companyMeeting.text=dicArray[indexPath.row][“Company”]as?字符串
cell.lblNews.text=dicArray[indexPath.row][“News”]as?字符串
cell.lblCommonKey.text=dicArray[indexPath.row][“CommonKey”]as?字符串
打印(扇形打印)
cell.imgViewFirst.ishiden=true
cell.lblCommonKey.ishiden=true
cell.btothers.tag=indexPath.row
//对于0中的i..放置else条件并将其从RemoveFormSuperview中删除如何实现此目的?因为单元格是重复使用的,所以它们将被替换。您需要根据模型在条件中添加一些其他属性,以检查您想要的特定单元格。@RaghavChopra放置完整代码将给出答案asap@SaeidBasirnia如果我不想要要使用这些单元格,如何使用新单元格