I've created side menu as shown in this..and I want image view only for the first row with full name label so that if anybody clicks on image view of the first row, allow the user to choose an image from the gallery. moreover, all other rows should contain only the text which redirects to another view controller. Please suggest any link or any piece of code get image view only on the first row of side menu with a button to choose an image from gallery. Here is my code
var arrdata = ["Full name", "Home", "Favourite", "Logout"]
var arrimg = [#imageLiteral(resourceName: "hello.png"), #imageLiteral(resourceName: "hello.png"), #imageLiteral(resourceName: "hello.png"), #imageLiteral(resourceName: "hello.png")]
@IBOutlet var sidebar: UITableView!
@IBOutlet var sideview: UIView!
var isSideViewOpen: Bool = false
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrdata.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
cell.img.image = arrimg[indexPath.row]
cell.lbl.text = arrdata[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 1
{
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let HomeViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! HomeViewController
self.present(HomeViewController, animated:true, completion:nil)
}
if indexPath.row == 3
{
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let ViewController = storyBoard.instantiateViewController(withIdentifier: "Login") as! ViewController
self.present(ViewController, animated:true, completion:nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
sideview.isHidden = true
sidebar.backgroundColor = UIColor.groupTableViewBackground
isSideViewOpen = false
}
First, you will need your custom cell that has an image and the text.
Guide for Custom Cells
After that i would recommend having a list for configuration like
let shouldShowImage = [true, false, false, false, ...]
In your function
cellForRowAt
you should check if your cell must show the image like