所以,我想把不同的图像放到tableview单元格中,我有3个不同的文件。我已经做了一些编码,但现在我有问题完成它。请看看我的代码并告诉我如何处理这个问题,我是新手。 (坚持了一整天)......这一点的重点是自定义单元格具有不同的图像和两个标签。
第一个文件
gulp.task('serve', function() {
browsersync.init({
port: 3001,
server: {
baseDir: './'
}
});
});
第二档
class MenuCells {
private var _cellTitle: String
private var _cellDetails: String
private var _cellIcon: Array<String>
var cellTitle: String {
return _cellTitle
}
var cellDetails: String {
return _cellDetails
}
var cellIcon: Array<String> {
return _cellIcon
}
init(cellTitle: String, cellDetails: String, cellIcon: Array<String>) {
_cellTitle = cellTitle
_cellDetails = cellDetails
_cellIcon = cellIcon
}
func cellData() {
_cellTitle = "x"
_cellDetails = "y"
_cellIcon = ["1","2","3","4"]
}
}
第三个文件(这里我卡住了,我不知道如何实现数据)
class MenuCell: UITableViewCell {
@IBOutlet weak var bg: UIView!
@IBOutlet weak var cellTitle: UILabel!
@IBOutlet weak var cellDetails: UILabel!
@IBOutlet weak var cellIcon: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}
func configureCell(menuCell: MenuCells) {
cellTitle.text = menuCell.cellTitle
cellDetails.text = menuCell.cellDetails
cellIcon.image = UIImage(named: "\(menuCell.cellIcon)")
}
}
答案 0 :(得分:1)
你需要做这样的事情。
awk -F'[ =]' ' # Set field separator space and =
{
# Loop through no of fields in record,
# NF gives no of fields in current record
for(i=1;i<=NF;i++)
# If field equal to foo then
if($i=="foo")
# print next(i+1) and 5th(i+5) field from current field index
print $(i+1),$(i+5)
}
' mylog # input file
并更改
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "menuCell", for: indexPath) as? MenuCell
// create object of MenuCells file and assign your variables.Instead of creating array of images in MenuCell, create array in this file and send image as a param 1-by-1.
let myMenuCells = MenuCells(cellTitle: "Title", cellDetails: "Details", cellIcon: image)
//By this below method set your data in your outlets. As this func is already doing so call it.
cell.configureCell(menuCell: myMenuCells)
return cell
}
至private var _cellIcon: Array<String>
,因为您只需将图片名称和private var _cellIcon: String
自动分配图片发送到您的插座。
func configureCell
至cellIcon.image = UIImage(named: "\(menuCell.cellIcon)")
答案 1 :(得分:0)
如果故事板中有原型单元格,则可以为每个原型单元格设置标识符,并使用if语句为每个单元格单独运行代码。 (因此,检查标识符是否用于单元格A,如果是,则运行单元格A的设置,否则运行单元格B的设置。)