Giter Club home page Giter Club logo

Comments (7)

macfanatic avatar macfanatic commented on July 18, 2024

I think that the table is created somewhere after the on_load is called, I would use something like:

class MenuScreen < PM::TableScreen
  def view_will_appear(animated)
    super
    view.backgroundColor = :red.uicolor
  end
end

from promotion.

forrestgrant avatar forrestgrant commented on July 18, 2024

Worked. Thanks!

from promotion.

macfanatic avatar macfanatic commented on July 18, 2024

No worries, glad to help. Love PM :)

from promotion.

jamonholmgren avatar jamonholmgren commented on July 18, 2024

I would recommend using will_appear rather than view_will_appear(animated) unless you need to know if the view will be animated. It gets called by view_will_appear anyway and doesn't need a call to super.

class MenuScreen < PM::TableScreen
  def will_appear
    view.backgroundColor = :red.uicolor
  end
end

on_load is actually not a very good event to be setting up your view on either Screen or TableScreen since it fires too early in the process.

Now, one thing to consider is that will_appear (and view_will_appear(anim)) will fire multiple times if you're flipping back and forth between it and another view. So if you want to avoid adding elements multiple times, set up something like this:

class MenuScreen < PM::TableScreen
  def will_appear
    @view_setup ||= begin
      view.backgroundColor = :red.uicolor
      true
    end
  end
end

This will only set up your view once.

We may want to build in a dedicated view setup method that gets called only once and allows you to create your views. Thoughts on that? Example:

class MenuScreen < PM::TableScreen
  def setup
    view.backgroundColor = :red.uicolor
  end
end

Open to other names, if this sounds like a good idea.

from promotion.

forrestgrant avatar forrestgrant commented on July 18, 2024

Always a help @jamonholmgren, Thanks for this awesome gem!

from promotion.

jamonholmgren avatar jamonholmgren commented on July 18, 2024

You bet -- glad it's been useful!

from promotion.

jamonholmgren avatar jamonholmgren commented on July 18, 2024

I'm going to table the setup method for now. It's an interesting idea but does run the risk of making ProMotion too automagical. One of the guidelines I loosely follow with ProMotion is the idea of making iOS development more ruby-like while not completely reinventing the paradigm...hence the Screen -> UIViewController equivalence, on_load roughly like viewDidLoad, etc.

But I'm open to the setup method if it would be useful and not too confusing to beginners.

from promotion.

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.