Replace UINavigation with UIToolbar? - iphone

I've built a Navigation-based app, but now that I'm knee-deep in the code, I've decided it would actually be best to have just a UIToolbar instead (only need modal views, not drill-downs). But extricating the Navigation stuff and replacing it with a Toolbar is causing me all sorts of grief...
Has anyone ever done this, and maybe has a pointer or two? Or even know of a walkthrough linked somewhere?
Thanks!

Bite the bullet and rewrite. Any guides out there will not be specific enough to your situation.
99 times out of a hundred if I realise I've made a massive design mistake and don't change it, I end up regretting it more than if I do. And since you'll take a copy/start from scratch again, you can always revert if you need to give up half way through!
Seriously, because this is a current app that is still (relatively) early in its development life and is all fresh in your mind it will very likely be quick to re-do. Also, sounds like this might be one of your first iPhone apps so you're likely learning new stuff every day - now you get to put all the new stuff in this app too. And finally, just imagine the work involved if you put another 200 hours into this as it is and then decided you had to rewrite!!
Hope that helps, and I bet you get it rewritten in less than a day!

Related

ios - Code VS Storyboard opinion

I have just spend a lot of hours re writing my app to have it all in code instead of using storyboard.
Mainly because I wanted to understand what the storyboard did for me.
Obviously with this, I have noticed that my files have become severely big in terms of lines of code.
Apple seems to be more in favor of storyboard then writing lines of code, as per their WWDC videos.
As fellow developers do you still feel that writing everything out in code is the better way to go? I hope to get a good few opinions on this as I want to see if my feelings on the matter are supported by your ideas, having done this for a longer period of time no doubt.
Thanks in advance.
There are few advantages and disadvantages of both.
Advantages of adding controls by Code
You can prefer writing everything to code if most of controls are dynamic. So that you can load controls whenever required.
Its easy to reuse code and make application more dynamic e.g you want to make UI themes for application
Advantages of Storyoard/ XIB
Using Storyboard/ XIB load all controls(Better if application is static) at once for that view you have to just bind properly.
Design UI with storyboard/ XIB is easy as compare to code.
These are few advantages of both as per my understanding.
making application through the code, helps developer lot, it gives flexibility.but going through the storyboard decreases lines of code. for mobile application development decreased number of lines codes or less code is always welcome.

iPhone xcode code vs interface builder

I've been using Xcode for a while and had a brief look at the interface builder when I first started but then went straight on to coding everything.
So far it's working OK but I just wondered if I'm missing something by not using the IB.
Is there any advantage to using the IB at all? I've even coded subviews and stuff without using the IB but I can't help thinking that it might be more advantageous to use it?
If not I'll keep on doing what I'm doing as it's working for me up to now :D
Thanks
If constructing everything in code is working for you, then great. Personally if it can be done in IB it's done in IB.
I'd be surprised if there's a best practice for this; everyone will have their opinion and preference.
I like to do UI related work in IB - if i'm dealing with presentational concerns I like to be in an environment that offers immediate visual feedback. It also cuts down the amount of boiler-plate code that you would have if constructing everything programmatically.
That said you can't do everything in IB. There are times you'll fall back on programatically constructing or laying out a view.
A little knowledge of both approaches goes a long way...
possible duplicate of: iphone app best practice - is using the IB a better way to design your app, or writing UI code on your own better?
at the end of the day its whatever you feel more comfortable doing. IB is horrible in my opinion, programming takes more effort - more thought. :)
I usually use IB, get immediate visual feedback and make the layout looks exactly easier. Only in one case that I have to give up with IB is performance with UITableView scrolling. In this case, the best solution I can find is to write code to draw everything in the cell using code. This makes the performance much better.
Generally, I recommend to use IB until you have some specific requirements like performance or you need to have really much control over the view
New projects always start off simple so people tend to gravitate toward IB naturally.
Personally I've found that as a view gets more dynamic and complex (and they always do), it makes sense to code it.
YMMV.

Good reasons why to not use XIB files?

Are there any good reasons why I should not use XIB / NIB files with an highly customized UI and extensive animations and super low memory footprint needs?
As a beginner I started with XIB. Then I figured out I couldn't do just about everything in them. It started to get really hard to customize things the way I wanted them to be. So at the end, I threw all my XIBs away and did it all programmatically.
So when someone asks me if XIB is good, I generally say: Yeah, if you want to make crappy boring interfaces and don't care too much about performance, go ahead. But what else could be a reason not to use XIB?
Am I the only iPhone developer who prefers doing everything programmatically for this reasons?
I think that Interface Builder is one of the biggest assets of Mac (and by extension, iPhone) software development. GUIs are visual; why not create them using a visual interface? IB is flexible enough that you can lay out an interface using its "generic" components, and then subclass them where necessary. Sure, if you have a unique interface you're going to have to subclass a view class and perform custom drawing, but you can also lay out your interface in IB and then easily use the inspector to switch the class to your custom subclass.
Honestly I think it's a spectrum of convenience. If you are comfortable writing everything in code then go for it. If you design your project well then it should be about the same amount of work creating new windows, etc. But I know that a lot of people aren't as comfortable with the GUI world so nib/xibs work well there.
I honestly find myself using XIBs as a base quite often and editing them with code to get the specific look I want. Personal preference.
For a specific con on that point, views can be difficult to configure after loading them from a xib. When you have conflicting settings between IB and code that can be nasty to troubleshoot.
Here's a question for the list. What is the performance hit to using a xib? I thought they were a plus because they don't get loaded into memory until you need them. That said, that load time is longer which will slow your program down. Thoughts?
One thing I found better about code is for the event connections on controls, when you search for uses of a method (message) you find them if they are coded and you don't find them if they were set in IB.
On the other hand laying out objects on a view is much easier in IB where you can see their size and positions. When you do that in code you have to guess at the size and origin settings and then run it and make adjustments, then run it again to see what it looks like.
When your application has some kind of "standard" views, go with the XIB. If you need real customization, depending on external content (XML...) do it programatically.
I started using XIBs and now it's all code, I find myself more comfortable this way. I had real problems with XIBs, and now writing the interfaces all in code really saves me time.
I save tons of time when dealing with UIControllers (UITabBarControllers, UINavigationControllers etc.) in the start up phase where all the navigation stuff is hooked up.
I just build X viewControllers with a accompanying XIB, throw in the stuff needed in IB, labels, images etc. This means that for almost any sort of app you can have a proof of concept up in a few hours. This is enough to justify spending some time learning the ins and outs of IB. Especially on the iPhone where you can have a ton of good UI ideas, but they all fail when they move from the Simulator to an actual device.
The best thing, in my mind, is to balance it out, if you find yourself using a lot of time doing the "change the frame 3 px -> compile -> ahh.. needs two pixels more -> change 2 px - compile -> ahh.. 1 more px" for something that could be done in IB, you will seriously start to waste time.
I start as above, but afterwards I often throw the XIBs away for custom stuff. The trick is to not spend hours on implementing versions of custom stuff in code over and over again, but figure out how it should be and do the custom stuff once:)
The XML content of a nib file is very complicated. This makes it extremely difficult to review changes or fix merge conflicts with a version control system like Git.
Interface Builder is a nice idea, but Bret Victor, in his talk "Inventing on Principle" and his essay "Learnable Programming," implicitly challenges Apple to build an even better IDE.
One idea, based on Bret Victor's principle: What if I could select a "Move Tool" in the iOS Simulator app that let me move a button in my app and then the frame code changed in the implementation (.m) file? This would be much better.

iphone application layout

I'm trying to get started with an iPhone application, I had a look around at other questions but i'm still sorta stuck so hopefully someone can help...
First thing is I'm totally confused with the whole view concept, I'm more used to visual studio so I'm going to use the term 'form' to describe what I have in my head.
I want to achieve a home screen in an application with say 9 icons (much like the iphone home screen) which each lead to a different 'form'. Each form may have a different function so say one might be a simple calculator, one might play a video etc.
How do I do this, its destroying my soul trying to do something so simple... If you guys even have any links to get me on the right track it would be greatly appreciated
I suggest you take a look at the Stanford iPhone Programming Course. If you don't have the time to look through it all, I reccommend at least Lectures 5 and 6 about Views and ViewControllers. The slides are quite instructive and they come with video presentations that should help you get on your way in about an hour.
Apple's samples are a great place to start. There are some simple ones that can show you how views and view controllers work.
Also, in Xcode, when you create a new iPhone app template, that template usually has enough code to display a view, and sometimes a flip-side view or more. Sometimes, you should stop reading, and do.
I had the same weird learning curve as you, as things don't initially seem to make sense but they do - and once you've got your head round them they make perfect sense trust me!
Your 'forms' are viewControllers in this M-V-C land, they control all the 'view' (which are controls or any object which can be seen) within them. Normally they are loaded from a Nib (design from the interface builder), but don't have to be.
The way I would go about your problem is to use a navigationController as the base to handle all of your view controllers.
A navigation controller needs a rootviewcontroller to start so this will be your desktop Viewcontroller. I'm not sure how you are planning to populate this but all the icons will need to be stored in some kind of array. I suggest you use a simple UIButton. When then button is pressed you then alloc and init and push the required view controller.

iPhone Bug App bug Question and challenge

Ok so I've got a really annoying bug in my app. It's driving me crazy and I'm sure it's beyond my skill level as I am learning as I go.
Here is the initial rundown of the bug: A shot in the dark - Application bug
However I have found a way to consistently reproduce the bug (only on the device not in the simulator)
First you create a new Pool and save it. Then add 20 blank time entires into one day. Save it and this is where the problems begin. (when you go back to the main detail view the tableview has put itself out of editing mode with being told to do so). Now if you go back to the day to see the time entries you just added they are still there.
If you go back to the main overall tableview listing all pools and now go back to the day you added the times they have dissapeared.
Add one time and it all saves fine. Add twenty and it doesn't save. WTF!!
Main Menu listing Pools:
Detail view:
Edit View:
Time Edit View:
Add a time:
I'd appreciate any more guesses. But as well as this question I'm offering a bounty of £25 (Sorry I'm a poor student) to whoever is good enough to fix this bug first!
if your interested my email is danmorgz[at]gmail.com
Thanks,
Dan
If you haven't already done so, I'd recommend turning on NSZombie support and seeing if you're using any of your objects after they've been freed. As far as I know this can be turned on in the simulator and on the device.
Most likely, you're failing to retain some object somewhere along the way. When an object gets released and then the memory is re-used for something else, you'll get all sorts of bad behavior, including crashes, or mysterious "disappearance" of other objects.
One thing you can try is putting breakpoints into the -dealloc method of your custom classes. Then you can see where they're getting deallocated from. Most likely though, this will end up being when the AutoreleasePool gets drained, which won't tell you much.
Alternatively, look into using some of the memory debugging tools built into Cocoa.
That document is for Mac OS X, but I think most all of this will work in the iPhone simulator, at least. I know that your bug "doesn't happen" in the simulator, but that really only means that the symptoms are different, and you're not noticing them.
Thanks for all your answers. It's now fixed.
For those interested I'd forgotten to add a cellidentifer in the XIB of my cell subclass.
cellForRow: method was therefore creating a new cell every time. The memory got filled up very quick. It then seemed as though my app was automatically trying to cut the fat by forcing another tableView out of editing mode and not managing my instances properly.
Again it's a memory problem. Isn't this always the case!?!
The clue was a one off 101 error in the console indicating my app was using too much memory. Oh and a slow scrolling tableView.