IBDesignable never finishes updating UITableViewCell in storyboard
This issue has been resolved as of Xcode 9.
I had reported this issue to Apple and at least have the piece of mind knowing that this is a known bug. It is currently an open issue under the problem ID 17973876.
Edit: As of 12/7/2016 this bug is still marked as open.
Swift 3: Designable table view cell
I think there are a couple of possible issues you can look into here. First, whenever you create a custom view you will need to associate it with the xib file name.
func setupNib(){
let bundle = Bundle(for: ProgressHeaderTableViewCell.self)
guard let customView = bundle.loadNibNamed("NAME_OF_XIB_FILE_GOES_HERE",owner: self, options: nil)?.first as? ProgressHeaderTableViewCell else {
return
}
customView.frame = self.bounds
self.addSubview(customView)
}
Also, whenever I work with xib files, I do any view setup within the awakeFromNib()
method after checking to make sure one of the expected elements is not nil.
override func awakeFromNib() {
if headerLabel != nil {
self.backgroundColor = UIColor.blue
self.headerLabel.text = "Hello world"
}
}
Finally, I've only been able to get IBDesignables to work when I wrap the setup functions with the a check that there are no current subviews:
override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
//check that there are no current subviews
if self.subviews.count == 0 {
self.setupNib()
}
}
// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//check that there are no current subviews
if self.subviews.count == 0 {
self.setupNib()
}
}
P.S When I was learning this, I found this blog post super helpful. You may want to read through it yourself to get a handle on IBDesignable and custom views. http://supereasyapps.com/blog/2014/12/15/create-an-ibdesignable-uiview-subclass-with-code-from-an-xib-file-in-xcode-6
IB Designables for storyboard UITableViewCell: Failed to render and update auto layout status for CountdownViewController The agent crashed
This is happening because your dummyView
is an IBOutlet
and is implicitly unwrapped. prepareForInterfaceBuilder
will be called before dummyView
is initialized. You can prevent a crash by changing your code to dummyView?.backgroundColor = .red
but then nothing will be rendered because dummyView == nil
.
It doesn't make a ton of sense to mix IBDesignable
with IBOutlet
. In general, IBDesignable
is meant to make run time layout and drawing visible at design time. But IBOutlets
are necessarily already visible at design time. This might however be desirable in a xib. For a discussion of that see here and here.
Navigate to ViewController from @IBDesignable UIView didSelectRowAt UITableView
Your UITableView
is a UIView
so it's not a UIViewController
and has not UINavigationController
.
You should create a delegate
in your UITableView
that will be implemented by your UIViewController
.
Something like that :
protocol MyTableViewDelegate: class {
func didSelectRow(url: String, titleText: String)
}
Add a delegate variable in your table view like :
weak var delegate: MyTableViewDelegate?
and call your delegate like this :
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let actionType = AppData?.items?[indexPath.row].actionType
switch actionType {
case 5:
print(actionType ?? 0)
let urlLink = AppData?.items?[indexPath.row].actionUrl
let titleText = AppData?.items?[indexPath.row].textValue
self.delegate.didSelectRow(url: url, titleText: titleText)
default:
print(actionType ?? 0)
}
}
In your view controller :
you should add your table view custom class into your ViewController,
then add delegate : yourTableView.delegate = self
implement delegate :
extension MyViewController: MyTableViewDelegate {
func didSelectRow(url: String, titleText: String) {
let vc = storyboard.instantiateViewController(withIdentifier: "WebViewController") as! WebViewController
vc.url = urlLink
vc.titleText = titleText
self.navigationController.pushViewController(vc, animated: true)
}
}
Related Topics
Arkit - How to Display the Feed from a Virtual Scncamera Placed on Scnplane
Swift: Make Translucent Overlapping Lines of the Same Color Not Change Color When Intersecting
What Does This Two Question Mark Mean
How to Deal with Buffered Strings from C in Swift
Text Overlapping Itself in Table Cells Swift
How to Access App Specific Folder and Use It to Backup or Some App Specific Data? in Swift
Swift. Get Binary String from an Integer
Swift 3 Init Method That Accepts JSON with Optional Parameters
Could Not Find an Overload for '+' That Accepts the Supplied Arguments
Identifiable Protocol in Swift: Class VS Struct
Deleting with One-To-Many Relationship
Swift:How to Handle a Lot of Textures in Memory
Avspeechsynthesizer Errors in iOS 10
Swift Probability of Random Number Being Selected
Uicollectionview Scrolltoitematindexpath, Not Loading Visible Cells Until Animation Complete
What Is Existentialmetatype in Swift