BFPaperTabBarController icon indicating copy to clipboard operation
BFPaperTabBarController copied to clipboard

create controller programmatically throws exception

Open thisiscam opened this issue 11 years ago • 14 comments

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?

thisiscam avatar Sep 17 '14 19:09 thisiscam

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

bfeher avatar Sep 18 '14 06:09 bfeher

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

thisiscam avatar Sep 18 '14 07:09 thisiscam

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 ;)

bfeher avatar Sep 18 '14 07:09 bfeher

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

thisiscam avatar Sep 18 '14 07:09 thisiscam

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

benvium avatar Oct 26 '14 19:10 benvium

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...

thisiscam avatar Oct 26 '14 19:10 thisiscam

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 [email protected] 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

benvium avatar Oct 26 '14 19:10 benvium

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

Timstarockz avatar Nov 30 '16 23:11 Timstarockz

@Timstarockz Thank you!

benvium avatar Dec 01 '16 08:12 benvium

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

bfeher avatar Dec 02 '16 00:12 bfeher

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

tobatha avatar Dec 06 '17 10:12 tobatha

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

bfeher avatar Dec 07 '17 00:12 bfeher

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

tobatha avatar Dec 07 '17 02:12 tobatha

@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 :)

bfeher avatar Dec 07 '17 02:12 bfeher