status_bar icon indicating copy to clipboard operation
status_bar copied to clipboard

base.rb:40:in `show_activity_notice:': undefined method `activity_view' for nil:NilClass (NoMethodError)

Open Pasta opened this issue 11 years ago • 5 comments

It seems that instantiating a Status::Base never enter inside this "every" block:

 timer = 0.1.second.every do
    return if App.shared.keyWindow == nil ||   App.shared.keyWindow.rootViewController == nil
    @view = StatusBar::View.new
    App.shared.keyWindow.rootViewController.view.addSubview(@view.view)
    App.shared.keyWindow.rootViewController.view.sendSubviewToBack(@view.view)
    timer.invalidate
  end 

And thus, never populate @view.

Probably because I do something like that:

statusbar = StatusBar::Base.new statusbar.show_activity_notice "MESSAGE!"

Maybe the only way to use your gem is to instantiate the Status::Base at least 0.1 second before calling it. Doesn't seem to be explained in the doc.

No time to fix that myself, so I just fill an issue.

Cheers,

Pasta avatar Dec 22 '13 04:12 Pasta

Why would you instantiate a status bar every 0.1 second? You instantiate a status bar once and then you can show messages when you need to show them.

Showing a message takes 0.3 seconds to slide down, so instantiating a status bar makes no sense.

You more than welcome to modify the README to make that more clear.

holgersindbaek avatar Dec 22 '13 04:12 holgersindbaek

I'm just saying that it seems that you cannot instantiate a statusBar and call show_activity_notice right after. I'm not saying that I instantiate a StatusBar every 0.1 second.

Executing those two lines:

statusbar = StatusBar::Base.new statusbar.show_activity_notice "MESSAGE!"

Takes less than 0.1 second, so the block you create on base.rb:9 doesn't have the time to fill the @view line 11 with a StatusBar::View, because you call it every 0.1 seconds.

So when you call statusbar.show_activity_notice "MESSAGE!", @view is nil.

But maybe I'm wrong, and I would like to know if I can use this gem the way I do it.

Cheers,

Pasta avatar Dec 22 '13 05:12 Pasta

Ok. The way I do it, is that I instantiate the status bar as one of the first things in the root view controller and then it’s ready to use whenever I need it.

All the best

Holger Sindbaek Holgersindbaek.com (http://Holgersindbaek.com)

Co-founder Uninkd.com (http://Uninkd.com) Meer.li (http://Meer.li)

On Sunday, December 22, 2013 at 6:35 AM, Vincent Coste wrote:

I'm just saying that it seems that you cannot instantiate a statusBar and call show_activity_notice right after. I'm not saying that I instantiate a StatusBar every 0.1 second. Executing those two lines: statusbar = StatusBar::Base.new statusbar.show_activity_notice "MESSAGE!"
Takes less than 0.1 second, so the block you create on base.rb:9 doesn't have the time to fill the @view (https://github.com/view) line 11 with a StatusBar::View, because you call it every 0.1 seconds. So when you call statusbar.show_activity_notice "MESSAGE!", @view (https://github.com/view) is nil.
But maybe I'm wrong, and I would like to know if I can use this gem the way I do it. Cheers,

— Reply to this email directly or view it on GitHub (https://github.com/holgersindbaek/status_bar/issues/2#issuecomment-31079430).

holgersindbaek avatar Dec 22 '13 12:12 holgersindbaek

I've the same problem. I create the instance on load and whenever I try to use any method got the same thing:

show_activity_notice:': undefined method activity_view' for nil:NilClass (NoMethodError)`

juanpujol avatar May 24 '14 15:05 juanpujol

Hmmm... I haven't looked at the gem for some time, but try to look at the source code for the initialisation of the activity bar.

I think I might have put a small delay into creating the view, so if you're trying to show a notice right after initialising the view, then it won't work.

The code is relative simple. Feel free to fork and improve.

holgersindbaek avatar May 24 '14 15:05 holgersindbaek