Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect size and location in UITableViewController #2

Closed
leongwq opened this issue Aug 12, 2015 · 10 comments
Closed

Incorrect size and location in UITableViewController #2

leongwq opened this issue Aug 12, 2015 · 10 comments

Comments

@leongwq
Copy link

leongwq commented Aug 12, 2015

After implementing the code, the location and size of the view is wrong. I am using a tableview

img_2782

@evgenyneu
Copy link
Owner

Hi, thanks for reporting, in which view do you access the dodo property?

@leongwq
Copy link
Author

leongwq commented Aug 13, 2015

Im accessing it in a UITableView controller.

This is my code in didSelectRowAtIndexPath self.view.dodo.success("Lock has been unlocked")

@evgenyneu
Copy link
Owner

Got it, can you check the bounds of the view in didSelectRowAtIndexPath for me?

view.layoutIfNeeded()
print(view.bounds)

@leongwq
Copy link
Author

leongwq commented Aug 13, 2015

(0.0, 0.0, 375.0, 667.0)

@evgenyneu
Copy link
Owner

Good, the size is non-zero. What if you remove view.layoutIfNeeded(), does it show same bounds?

@evgenyneu
Copy link
Owner

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?

@leongwq
Copy link
Author

leongwq commented Aug 13, 2015

Adding the view to a NavigationController seems to do the trick.

self.navigationController!.view.dodo.success("Connected to lock")

However this only works if the TableViewController is embedded in a NavigationController

img_2789

@evgenyneu
Copy link
Owner

Ah, good thinking. I will leave this ticket open, so others can contribute.

@rzubeldia
Copy link

@leongwq Thanks for your trick :
self.navigationController!.view.dodo.success("Connected to lock")

Is working perfect

@evgenyneu evgenyneu changed the title Incorrect size and location Incorrect size and location in UITableViewController Apr 1, 2016
@vincenthuangenyu
Copy link

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)

@leongwq leongwq closed this as completed Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants