简体   繁体   中英

images in tableViewCells that are in Sections (swift 3- Xcode 8.3.2)

Hi I have a table view And want to make it like a picture below

带节的TableView

here is the code that I used ( the problem is that I can't see the picture of each cells :

var menuImage = ["Add.png" , "Menu.png" , "Add.png" , "Add.png" , "Add.png" , "Add.png" ]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel!.text = listSetting[indexPath.section][indexPath.row]
    cell.preservesSuperviewLayoutMargins = false
    cell.separatorInset = UIEdgeInsets.zero
    cell.layoutMargins = UIEdgeInsets.zero
    cell.textLabel?.textAlignment = .right
    cell.textLabel?.font = UIFont.init(name: "IRANSans", size: 14)
    cell.imageView?.image = UIImage.init(named: menuImage[indexPath.row])

    return cell

}

the second problem Is that I want to detect which cells has pressed here is the code that I used But Didn't work :

func tableView(_ tableView: UITableView, didSelectRowAt listSetting: IndexPath) {

        print("Remove Adds")


        if listSetting.section == 1 && listSetting.row == 1{
            //Code to implement View Controller to remove adds
            print("Cell4 pressed")
        }

Open Main.storyboard, select the cell and in the Size Inspector change the Row Height to 140 (as per your need-Check in storyboard) Now in viewDidLoad()type this code,use UITableViewAutomaticDimension method:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140 //as per your need 

and mention this reloadData().

self.tableView.reloadData()

More checkout below link:

https://www.raywenderlich.com/129059/self-sizing-table-view-cells

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM