bfeher / BFPaperTabBarController

iOS UITabBar (controller) inspired by Google's Paper Material Design.
MIT License
342 stars 46 forks source link

create controller programmatically throws exception #3

Open thisiscam opened 9 years ago

thisiscam commented 9 years ago

I'm experimenting with this controller and figured that it raises NSRange out of bound exception when calling alloc init. it seems that alloc init somehow calls initwithnib, which I don't have any. Is this control only supposed to be used with storyboard?

bfeher commented 9 years ago

Hmm I see. I found where and why it's crashing and I'm thinking of how best to fix this. It crashes because it tries to calculate where to draw the underline before there are even any tabs loaded.

For now I guess it's only usable via storyboard :/

Incidentally, UITabBarControllers always call their initWithNib from within their init methods. Try the same code you have only without subclassing BFPaperTabBarController and you will see, it will call its initWithNib from within init:

2014-09-18 15:11:37.136 bfpapertabbarcontrollerTEST[1324:60b] init start
2014-09-18 15:11:37.136 bfpapertabbarcontrollerTEST[1324:60b] nib start
2014-09-18 15:11:37.137 bfpapertabbarcontrollerTEST[1324:60b] nib end
2014-09-18 15:11:37.138 bfpapertabbarcontrollerTEST[1324:60b] init end
thisiscam commented 9 years ago

Yeah I have the same observation

Thanks for that insight I suspect something similar earlier but just haven't got the time to test it out. I will just try to use a temporary hack for this for now and if you have any follow up(or there's anything I can help) please let me know

bfeher commented 9 years ago

I have to admit that I am not used to using TabBarController programmatically. I'm always open to accepting pull requests if you happen to figure out a good way to fix this. I will also keep looking into it but I can't promise any timeframe ;)

thisiscam commented 9 years ago

That's fine. I will definitely pull request if I find good solution. Right now I'm just deleting that initWithNib for this control so that it won't be called

benvium commented 9 years ago

@thisiscam Did you ever get this working programmatically? I tried deleting the initWithNib method with no luck

thisiscam commented 9 years ago

You might want to diff with this https://github.com/thisiscam/BFPaperTabBarController/blob/master/Classes/BFPaperTabBarController.m ? I remember commenting out a few lines in init which was super hacky...

benvium commented 9 years ago

Thanks for the quick response. I had a look at that’s basically what I did too. Not sure why mine isn’t working, I get no theming or ‘tap ripples’ or anything. Will have to try again when I have more time.

On Sun, Oct 26, 2014 at 7:05 PM, Cambridge notifications@github.com wrote:

You might want to diff with this https://github.com/thisiscam/BFPaperTabBarController/blob/master/Classes/BFPaperTabBarController.m ? I remember commenting out a few lines in init which was super hacky...

Reply to this email directly or view it on GitHub: https://github.com/bfeher/BFPaperTabBarController/issues/3#issuecomment-60528027

Timstarockz commented 7 years ago

If it's not too late, I've modified this class to work programmatically! You can check out the source here! I basically removed all references to IB and refactored/reorganized some of the initialization methods. Now it works like a charm without IB!

https://github.com/Timstarockz/BFPaperTabBarController/tree/master/Classes

benvium commented 7 years ago

@Timstarockz Thank you!

bfeher commented 7 years ago

@Timstarockz Thanks! I'll take a closer look next week and perhaps make this the standard.

tobatha commented 6 years ago

@bfeher so rite now with the latest version, init tab bar controller programmatically is possible?

bfeher commented 6 years ago

@tobatha It hasn't been integrated into the main branch, so please use Timstarockz version above. Thank you.

tobatha commented 6 years ago

@bfeher yeah, i tried last nite, seems no luck, but won't crash anymore, that's very reassuring! ^_^

bfeher commented 6 years ago

@tobatha I'm sorry that I have been criminally negligent of my repos lately. Life is getting too busy. If you find anything that needs fixed please let me know and I will try to fix it ASAP :)