GithubHelp home page GithubHelp logo

Show without view controller? about toast HOT 2 CLOSED

scalessec avatar scalessec commented on August 23, 2024
Show without view controller?

from toast.

Comments (2)

scalessec avatar scalessec commented on August 23, 2024

Hey Tyler, I think you're confusing controllers and views. Toast can care less about controllers, all it needs is a view to be presented in.

If self is a UIViewController, and you use [self makeToast:@"Hello World"], you're going to get an error. You need to use [self.view makeToast:@"Hello World"], which references the view property assigned to that controller, not the controller itself.

There's a few ways to do what you want. If you're using a UINavigationController, you can just display the toast in the navigation controller's container view. Then it doesn't matter if view controllers are being pushed/popped from the stack. You can do that like this:

[self.navigationController.view makeToast:@"Hello World"];

Another thing you can do is add the toast directly to the window (since UIWindow inherits from UIView). This is useful if you're not using a navigation controller:

[self.view.window makeToast:@"Hello World"];

Generally, it's bad practice to add something directly to the UIWindow unless you really need to so if you're using a navigation controller, use the first method. Hope that helps.

Charles

from toast.

tylercollier avatar tylercollier commented on August 23, 2024

Thanks Charles! You're right, I did mean the view controller's view, not the view controller itself. I didn't think of using the navigation controller, good one!

from toast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.