ios - 如何设置侧边栏中表格 View 单元格的第一行与所有其他行不同 - swift

标签 ios iphone uitableview swift4 xcode9.4

我已经创建了侧边菜单,如 this 所示。 ..我只希望第一行带有全名标签的 ImageView ,这样如果有人点击第一行的 ImageView ,允许用户从图库中选择图像。此外,所有其他行应该只包含重定向到另一个 View Controller 的文本。请建议任何链接或任何代码段仅在侧面菜单的第一行获取 ImageView ,并带有一个按钮以从图库中选择图像。这是我的代码

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
    }

最佳答案

首先,您需要包含图像和文本的自定义单元格。

Guide for Custom Cells

之后我建议有一个配置列表,例如

let shouldShowImage = [true, false, false, false, ...]

在您的函数cellForRowAt中,您应该检查您的单元格是否必须显示类似的图像

if shouldShowImage[indexPath.row] {

    cell.img.image = arrimg[indexPath.row]
} else {

    cell.img.isHidden = true
}

cell.lbl.text = arrdata[indexPath.row]

关于ios - 如何设置侧边栏中表格 View 单元格的第一行与所有其他行不同 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53428918/

相关文章:

objective-c - 如何在 UICollection 补充 View 中使用 UIButton?

iphone - 实现 Mobclix 时出错

ios - 自定义 UITableView 分隔符在 View 加载时正确显示,但在单元格滚动出 View 并返回时默认为不需要的行为

iphone - 如何使 UISegmentedControl 像 UITabBarController 一样工作?

ios - UITableViewCell 中的 UITextView 在选择单元格时隐藏光标

iphone - 无法通过邮件发送 csv 文件附件

iphone - 删除非空文件夹和特定文件类型

iphone - 滚动、缩放 UIScrollView 和界面方向旋转。如何使用自动调整大小等

iphone - UITableView 自定义单元格显示奇怪的结果?

ios - 使用发送自定义按钮在 UITableview 中的新行中插入数据