0

with the help of this Thread I managed to alter the font of my UITableViewCellActionButtons, but now the line-separator for each cell only gets visible after swiping the cell once and the disclosure indicators never show up. Here is my extension-code:

extension UITableViewCell{
    override open func layoutSubviews() {
        super.layoutSubviews()

        for subview in self.subviews {
            for sub in subview.subviews {
                if String(describing: sub).range(of: "UITableViewCellActionButton") != nil {
                    for view in sub.subviews {
                        if String(describing: view).range(of: "UIButtonLabel") != nil {
                            if let label = view as? UILabel {
                                label.font = UIFont(name: "CaptureSmallz", size: label.font.pointSize)
                            }
                        }
                    }
                }
            }
        }
    }
}

My cellforRowAt looks like this:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "planNameCell", for: indexPath)
    ...

    cell.textLabel?.text = ...
    cell.detailTextLabel?.text =  ...

    cell.selectionStyle = UITableViewCellSelectionStyle.none

    let textLabelFontSize = cell.textLabel?.font.pointSize
    cell.textLabel?.font = UIFont(name: "CaptureSmallz", size: textLabelFontSize!)!
    cell.textLabel?.sizeToFit()
    let detailLabelFontSize = cell.detailTextLabel?.font.pointSize
    cell.detailTextLabel?.font = UIFont(name: "CaptureSmallz", size: detailLabelFontSize!)!
    cell.detailTextLabel?.sizeToFit()

    return cell
}

I hope somebody knows what I messed up here. Thanks for the help!

//Edit 1: I've checked the view hierachy with the Xcode-Debugger, but it shows only a blank screen. But I can see the hierachy on the left side: see this screenshot // this is the state of the app I debugged

I noticed that there arent any views for the disclosure indicators and when I swipe left on a cell once the line separator appears and one _UITableViewCellSeparatorView entry gets added in the view hierachy. But I still don't know where to look now.

//Edit 2: I'm currently trying to get rid of the extension and call the code in it manually, but I can`t figure it out where to put it. I tried "viewDidAppear", but then the "UITableViewCellActionButton" aren't there yet. Is there a way to call function right after "editActionsForRowAt" has been called?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
LarsGvB
  • 267
  • 3
  • 11
  • This code is very hairy because you're trying to use a vanilla `UITableViewCell` and do a bunch of mucking around inside `layoutSubviews`. If you created a subclass called `PlanNameCell` and gave it a bunch of named properties you wouldn't have to do this — you could set the values for fonts, etc. once and forget about it. – jefflovejapan Nov 19 '17 at 17:07
  • @jefflovejapan: No, the UITableViewCellActionButton can't be changed within Xcode or directly without this extension (looked in many other Threads here on stackoverflow). So the prblem would remain even if I use a custom subclass for the cell. – LarsGvB Nov 19 '17 at 17:44
  • What is a `UITableViewCellActionButton`? I don't see a reference to it in Apple's documentation. Is it the accessory view on the right hand side? – jefflovejapan Nov 19 '17 at 17:52
  • I had a similar issue when altering UIPickerTableView in UIPickerView, in the tableview there should be one or two "_UITableViewCellSeparatorView" views that are sibling views to "UITableViewCellContentView". check your view hierarchy in the debugger when the issue occurs and see if they are being covered up by another view that could have been shifted from .sizeToFit() or dequeue-ing. Once you get to the root cause of the issue i'm sure it will be easy to fix using the unwrapping method above. cheers! – RLoniello Nov 19 '17 at 19:45
  • @jefflovejapan Those are the buttons you can add to a tableviewcell which appear if the user swipes to the left over the cell. – LarsGvB Nov 20 '17 at 10:08
  • @Ercell0 Ok thanks for the tip. I'll try that, although I`m pretty new to Xcode etc., but I guess I'll find some instructions around here how to easily look at the view hierachy at a given point. – LarsGvB Nov 20 '17 at 10:10
  • @Ercell0 I updated my question with some additional information. Hope you can give me another tip. – LarsGvB Nov 20 '17 at 10:55
  • Oh, I didn’t realize you where that new to iOS development. I recommend you get familiar with uicollectionview instead it can implement all of the features of uitableview and more. In your situation you can have a vertical scrolling collection view cell that holds another horizontally scrolling cell with a button that is ‘hidden’ off screen. these cell-views are uiviews that are completely customizable and dequeue-able. [check out this tutorial it’ll get you pretty close.](https://youtu.be/Ko9oNhlTwH0) – RLoniello Nov 20 '17 at 11:20
  • @Ercell0 I'd like to get this to work, because I already have a bunch of tables designed like this and this is the only problem I have (without the extension everything works like charm). Also I want to know why this happens because of education purposes. So if you would take a look at the hierachy I posted and give me a hint on what to try next to find the issue I'd really appreciate it. – LarsGvB Nov 20 '17 at 11:31
  • @Ercell0 See my second edit, please. – LarsGvB Nov 20 '17 at 12:47

0 Answers0