Я дошел до установки изображения (если он доступен), но по какой-то причине я не могу установить размер изображения для изображения (если у него есть изображение или на хотя бы рубильник предварительный просмотр) я пытался что-то вдоль линий thisНевозможно установить изображение для UIImageView в UITableViewCell
Но как вы можете видеть, изображение в конечном итоге занимает всю ячейку, не знает, почему ...
Вот что макет должен выглядеть ... Я попытался найти аспект заполнения ... но конечный результат примерно такой же ...
Редактировать: добавлен код, я забыл добавить ..., что очень поможет?
Установка на tabeview клетки
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell{
var cell:commentTableViewCell
if commentList[indexPath.row].cellType == 1{
//drink
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "drink",for: indexPath) as! commentTableViewCell
cell.drinkName.text = commentList[indexPath.row].commentOwner
cell.drinkPrice.text = commentList[indexPath.row].comment
return cell
}
else{
//comment
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "comment",for: indexPath) as! commentTableViewCell
cell.ownerTitle.text = commentList[indexPath.row].commentOwner
cell.commentContent.text = commentList[indexPath.row].comment
if commentList[indexPath.row].isFile{
//cell.imageView!.contentMode = UIViewContentMode.scaleAspectFill
cell.imageView!.image = commentList[indexPath.row].imageFile
}
else if !commentList[indexPath.row].isFile {
cell.imageView!.image = nil
cell.imageView!.removeFromSuperview()
}
return cell
}
}
The parsequery:
func getLocalComments(point:PFGeoPoint){
var temp = [CommentDetails]()
DispatchQueue.global(qos: .background).async {
let qComments = PFQuery(className: "UserCommentary")
let qDrinks = PFQuery(className: "venueDrinks")
if self.type == "House Parties"{
//Query the bars
qDrinks.whereKey("venueName", equalTo: self.id)
qDrinks.whereKey("venueID", equalTo: self.venueName)
qDrinks.addDescendingOrder("createdAt")
qComments.whereKey("venueID", equalTo: self.id)
qComments.whereKey("venueName", equalTo: self.venueName)
do{
let qReply1 = try qDrinks.findObjects()
if qReply1.count>0{
let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0)
var i = 0
while i < 2 {
let item = qReply1[i]
print(item)
comment.cellType = 2
i+=1
}
//temp.append(comment)
}
let qReply2 = try qComments.findObjects()
for item in qReply2{
let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0)
comment.commentOwner = item.object(forKey: "owner") as! String
comment.comment = item.object(forKey: "comment") as! String
comment.isFile = item.object(forKey: "image") as! Bool
if comment.isFile {
let dataPhoto:PFFile = item.object(forKey: "imgFile") as! PFFile
let imageData:NSData = try dataPhoto.getData()
let image:UIImage = UIImage(data:imageData as Data)!
comment.imageFile = image
comment.cellType = 2
}
temp.append(comment)
}
}
catch{
print(error)
}
}
DispatchQueue.main.async {
print(temp)
self.commentList.removeAll()
self.commentList = temp
self.commentTableView.reloadData()
}
}
}
Я хочу, чтобы изображение соответствовало аспекту, поэтому оно заполняет изображение, но не отображает изображение в полном объеме. –
Аспект подходит отображает изображение в полном объеме («подходит»). – matt
О, так есть способ сделать изображение подходящим для изображения? Извините, некоторые из них кажутся немного запутанными. Должен ли я каждый раз изменять размер изображения, чтобы он соответствовал критериям изображения? –