Incorrect size and location in UITableViewController
leongwq opened this issue · 10 comments
Hi, thanks for reporting, in which view
do you access the dodo
property?
Im accessing it in a UITableView controller.
This is my code in didSelectRowAtIndexPath self.view.dodo.success("Lock has been unlocked")
Got it, can you check the bounds of the view in didSelectRowAtIndexPath
for me?
view.layoutIfNeeded()
print(view.bounds)
(0.0, 0.0, 375.0, 667.0)
Good, the size is non-zero. What if you remove view.layoutIfNeeded()
, does it show same bounds?
It looks like Dodo can not be used in UITableViewController. UITableViewController sets a UITableView as its root view. Dodo adds a subview to the UITableView when a message is displayed. But it looks like UITableView does not like when subviews are added to it manually.
http://stackoverflow.com/questions/4641879/how-to-add-a-uiview-above-the-current-uitableviewcontroller
http://stackoverflow.com/questions/4403385/add-a-subview-in-a-uitableviewcontroller
http://stackoverflow.com/questions/18577569/add-view-over-tableview-uitableviewcontroller
A solution to this would be to use plain UIViewController instead of UITableViewController and add a UITableView to it in the storyboard.
I know it sucks, sorry. I added a notice about this problem to the README. Does anybody know how to use Dodo with UITableViewController?
Ah, good thinking. I will leave this ticket open, so others can contribute.
@leongwq Thanks for your trick :
self.navigationController!.view.dodo.success("Connected to lock")
Is working perfect
extension String {
var stringWidth: CGFloat {
let constraintRect = CGSize(width: UIScreen.main.bounds.width, height: .greatestFiniteMagnitude)
let boundingBox = self.trimmingCharacters(in: .whitespacesAndNewlines).boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14)], context: nil)
return boundingBox.width
}
}
let width = (self.tableView.frame.width - message.stringWidth - 5) / 2
self.view.dodo.style.bar.marginToSuperview = CGSize(width: width, height: 15)