【问题标题】:segmented control with tableView, disable UIImage Cell in the second and the third segment用tableView进行分段控制,在第二段和第三段禁用UIImage Cell
【发布时间】:2015-11-14 18:29:05
【问题描述】:

我想在特定的段控件中禁用 UIImage Cell,因为 0 段中的所有图像都显示在第二段和第三段中

2)第二个问题:如何将表格视图中的 UIImage 的大小更改为圆形? 请在下面找到我的段控制代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
    let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell
        switch(mySegmentedControl.selectedSegmentIndex)
        {
        case 0 :
                myCell.textLabel?.text = example1[indexPath.row] as? String
                myCell.imageView?.image = images[indexPath.row]
            break
        case 1 :
            myCell.textLabel?.text = example2[indexPath.row] as? String
            break
        case 2 :
            myCell.textLabel?.text = example3[indexPath.row] as? String
            break
        default:
            break
        }
    return myCell
    }

【问题讨论】:

    标签: swift uitableview uisegmentedcontrol


    【解决方案1】:

    如果在显示第一种情况时设置了单元格出列队列,则图像将在那里,因此对于其他情况,您必须将其设置为 nil。

        switch(mySegmentedControl.selectedSegmentIndex)
        {
        case 0 :
            myCell.textLabel?.text = example1[indexPath.row] as? String
            myCell.imageView?.image = images[indexPath.row]
        case 1 :
            myCell.textLabel?.text = example2[indexPath.row] as? String
            myCell.imageView?.image = nil
        case 2 :
            myCell.textLabel?.text = example3[indexPath.row] as? String
            myCell.imageView?.image = nil
        default:
            break
        }
    

    2) 将单元格出列后尝试此操作

    myCell.imageView?.layer.cornerRadius = myCell.imageView?.frame.width / 2
    

    【讨论】:

    • @moryia 非常感谢!你能回答我的第二个问题吗?我会接受你的回答!再次感谢
    • 我做了类似的事情,但我仍然有同样的问题 myCell.imageView?.frame = CGRect(x: myCell.imageView!.frame.origin.x, y: myCell.imageView!.frame .origin.y,宽度:20,高度:20)
    • 可能有一种方法可以使用标准单元格执行此操作,但此时最好使用您根据图像大小偏好构建的 xib 创建自定义单元格。 stackoverflow.com/questions/28489720/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多