我有一个带有自定义单元格的tableView
。每个单元格中都有一个pictureView
,但根据用户是否张贴图片,可能不会显示tableView
。但是现在当我在此pictureViews
内向下滚动然后向上滚动时,protocol ItemCellDelegate: NSObjectProtocol {
func photoButton(cell: ItemCell)
func adjustTextButton(cell: ItemCell)
func repostButton(cell: ItemCell)
func commentButton(cell: ItemCell)
func actionButton(cell: ItemCell)
func pictureView(cell: ItemCell)
}
func updateCell(with item: Item) {
......
if (item.getImgUrl().count != 0) { // Has picture
print ("show pictureView getImgUrl: " + item.getImgUrl())
self.pictureView.isHidden = false
let imageUrl = URL(string: item.getImgUrl())
self.pictureView.sd_setImage(with: imageUrl, completed: nil)
} else { // Has no pictures
print ("NO show pictureView getImgUrl: " + item.getImgUrl())
self.pictureView.isHidden = true
self.pictureViewHeight.constant = 0
}
......
}
消失了。
我应该做些什么改变?
谢谢!
我使用Swift 4和Xcode 10.1。
//自定义手机
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor(red:0.30, green:0.30, blue:0.30, alpha:1.0)]
self.navigationController?.navigationBar.tintColor = UIColor(red:0.30, green:0.30, blue:0.30, alpha:1.0)
self.navigationController?.navigationBar.shadowImage = UIImage()
tableView.estimatedRowHeight = 250
tableView.rowHeight = UITableView.automaticDimension
DispatchQueue.main.async() {
self.refresh(sender: self)
self.tableView.reloadData()
}
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
}
if ((profileId == iApp.sharedInstance.getId() && pageId == Constants.ITEMS_PROFILE_PAGE) || pageId == Constants.ITEMS_FEED_PAGE || pageId == Constants.ITEMS_STREAM_PAGE) {
let newItemButton = UIBarButtonItem(barButtonSystemItem: .add , target: self, action: #selector(newItem))
self.navigationItem.rightBarButtonItem = newItemButton
}
// add tableview delegate
tableView.delegate = self
tableView.dataSource = self
self.tableView.tableFooterView = UIView()
self.refreshControl.addTarget(self, action: #selector(refresh), for: UIControl.Event.valueChanged)
self.tableView.addSubview(refreshControl)
self.tableView.alwaysBounceVertical = true
// prepare for loading data
self.showLoadingScreen()
// start loading data
self.loadData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell
cell.delegate = self
cell.updateCell(with: items[indexPath.row])
cell.showRepostButton.isUserInteractionEnabled = true
return cell
}
//视图控制器
this.drawNextOuptutPictureGL = function (par) {
var gl = this.contextGL;
var texturePosBuffer = this.texturePosBuffer;
var uTexturePosBuffer = this.uTexturePosBuffer;
var vTexturePosBuffer = this.vTexturePosBuffer;
var yTextureRef = this.yTextureRef;
var uTextureRef = this.uTextureRef;
var vTextureRef = this.vTextureRef;
var width = this.width;
var height = this.height;
var yData = par.yData;
var uData = par.uData;
var vData = par.vData;
var yDataPerRow = par.yDataPerRow || width;
var yRowCnt = par.yRowCnt || height;
var uDataPerRow = par.uDataPerRow || (width / 2);
var uRowCnt = par.uRowCnt || (height / 2);
var vDataPerRow = par.vDataPerRow || uDataPerRow;
var vRowCnt = par.vRowCnt || uRowCnt;
var viewportRow = par.viewportRow;
var viewportColumn = par.viewportColumn;
// Calculate coordinates basing on a square matrix
var square = Math.sqrt(this.viewports.length);
var x = (this.canvasElement.width / square) * (viewportColumn - 1);
var y = (this.canvasElement.height / square) * (square - viewportRow);
gl.viewport(x, y, width, height);
var tTop = 0;
var tLeft = 0;
var tBottom = height / yRowCnt;
var tRight = width / yDataPerRow;
var texturePosValues = new Float32Array([tRight, tTop, tLeft, tTop, tRight, tBottom, tLeft, tBottom]);
gl.bindBuffer(gl.ARRAY_BUFFER, texturePosBuffer);
gl.bufferData(gl.ARRAY_BUFFER, texturePosValues, gl.DYNAMIC_DRAW);
if (this.customYUV444) {
tBottom = height / uRowCnt;
tRight = width / uDataPerRow;
} else {
tBottom = (height / 2) / uRowCnt;
tRight = (width / 2) / uDataPerRow;
};
var uTexturePosValues = new Float32Array([tRight, tTop, tLeft, tTop, tRight, tBottom, tLeft, tBottom]);
gl.bindBuffer(gl.ARRAY_BUFFER, uTexturePosBuffer);
gl.bufferData(gl.ARRAY_BUFFER, uTexturePosValues, gl.DYNAMIC_DRAW);
if (this.customYUV444) {
tBottom = height / vRowCnt;
tRight = width / vDataPerRow;
} else {
tBottom = (height / 2) / vRowCnt;
tRight = (width / 2) / vDataPerRow;
};
var vTexturePosValues = new Float32Array([tRight, tTop, tLeft, tTop, tRight, tBottom, tLeft, tBottom]);
gl.bindBuffer(gl.ARRAY_BUFFER, vTexturePosBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vTexturePosValues, gl.DYNAMIC_DRAW);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, yTextureRef);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, yDataPerRow, yRowCnt, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, yData);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, uTextureRef);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, uDataPerRow, uRowCnt, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uData);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, vTextureRef);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, vDataPerRow, vRowCnt, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, vData);
// draw image
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
答案 0 :(得分:0)
您应该为约束设置一个正常数,因为单元格已出队,如果您得到的任何人都没有url的另一个具有,则它的常数= 0,因此它将看起来是隐藏的
if (item.getImgUrl().count != 0) { // Has picture
print ("show pictureView getImgUrl: " + item.getImgUrl())
self.pictureView.isHidden = false
self.pictureViewHeight.constant = 50 << here some value
let imageUrl = URL(string: item.getImgUrl())
self.pictureView.sd_setImage(with: imageUrl, completed: nil)
} else { // Has no pictures
print ("NO show pictureView getImgUrl: " + item.getImgUrl())
self.pictureView.isHidden = true
self.pictureViewHeight.constant = 0
}
func updateCell(with item: Item) {
通话结束
self.layoutIfNeeded()