I recently started to learn Obj-C, and I try to write my first "bigger" app.
I want to have application that's structured similarly to Facebook, as in:
First thing user sees is login/register screen,
if he's logged in correctly, he sees main app screen, which can do many not-so-directly-related things.
I don't know how to structure that app TheRightWay.
First thing that comes to mind is setting subclassed UINavigationController as initial view controller, with one segue to 'log in' flow, and second to 'logged in' flow.
But that creates different problem: since (at least from my understanding), I shouldn't use modal segues to transition between different parts of app, would I need to use a chain of UINaviationController over and over? That seems like the 'easy way', but I'm pretty sure that's the wrong way.
This is question is as much about your development workflow as structure.
The structure of iOS applications is tightly coupled with the user-interface - so that should be your starting point.
Since you're using iOS 5, created a story-board - which captures the user interaction through a series of views - is what you do first.
Associated with each view is a ViewController - which is instantiated by the framework as required. In most cases, the structure of your application is going to hang beneath this.
Related
Background:
I currently have a NSTimer running in my AppDel class (I also have a method to calculate the amount of time my app spends in the background and adds it to the total, in case anyone brings this up).
The timer is checked at different intervals to see if it has reached 12 hours, at 12 hours the app needs to refresh its data from the server.
When this occurs, I need to display a UIAlert which when its button is pressed:
• Pops off view controllers to the first view controller.
This “refresh” should only be able to occur on 3 (specific)view controllers out of 7 within my app.
The Question(s):
Is NSNotifcationCenter sufficient for my requirements?
Where I would add an observer only to the view controllers I want this to occur on?
Is there a better approach I should be taking?
ya you can implement the NSNotifcationCenter approach but best alternative is to use custom delegate approach .By this way your app will work according to apple guidelines and memory utilisation of app is also less.
Using NSNotificationCenter is a good approach when you need to send information about some event (for example need of refreshing app) and you want to make as few changes as possible, without redesign all app architecture. I recommend you https://github.com/AllinMobile/AIMObservers because is created to facilitate the work with NSNotificationCenter and NSNotification.
Lately I have been playing around with the bluetooth framework and grew a strong enough knowledge to start building an application. The only problem is that all the examples I found and all the practice I have made consist in putting the core bluetooth core code inside the same file as the UIView with which the user is interacting.
I would like my future application to have multiple views in which the BLE scan occurs on the background. I initially thought about creating an object with a name similar to bleDeviceFinder and pass this object through each view. However, after thinking about it I realised that if I want something to happen in the current view I need the function didDiscoverPeripheral to have direct access to the UIView objects which it is supposed to affect.
I know it is probably a stupid question, what would be the best way to do so? I was thinking maybe to set and alert and subscribe every view to that alert; is this a good solution?
A quasi singleton BTLEManager that you pass around in the app. It sends NSNotifications for events like discovery, and your ViewControllers observe these notifications. The truth (i.e. list of discovered devices) stays in BTLEManager. Once a viewController has received such a notification it asks the BTLEManager for the list of current devices and then the viewController changes your views accordingly. The Views should never talk to the BTLEManager directly.
That's how I would do it.
I'm fairly new to Objective-C and cocoa programming, so I don't really understand the concept of App Delegates.
When we create a cocoa application, do we store our code (Methods, actions, outlets) in the App Delegate files or do we create a new file that will act as a controller and code from there. Right now, I put all of my code in those two files, but from what I read, your goal is to try to make your App Delegate files as slim as possible.
My question is: What's the usage of the app delegate files?
Talking about applicationDidFinishLaunching::
It's just your application entry point. Normally you only create the window and your first ViewController, or your Tabbar - your main starting interface class - here.
All the other delegate methods of the NSApplicationDelegate have other functions of course. Most of them are the point, where you react on the state of the app. Opened / Closed / Backgrounded / Reopened etc.
But you should probably have a look at the programming tutorials in the iPhone documentation. There is a lot of information on how to structure your objc projects. E.g. look here: Start Developing iOS Apps Today
Or if your looking for OSX Apps, look here:
1) Your First Mac App
2) Mac App Programming Guide
There is also a bunch of Sample code.
The App Delegate is a handler location to handle events that occur on the application. Things like open and close. It also hangs around the whole time the application is executing and you can grab the singleton instance at any point by doing [[NSApplication sharedApplication] delegate].
This comes in handy for handing objects between controllers and serving as a router for events. You can also store some data on the delegate if you need to modify/have access to it in different parts of the code.
This all works well for simple applications, but as things become more complex, you need to have some division of responsibilities. The AppDelegate should really only be responsible for actions that occur on the application itself, not on another view or a controller. Putting all/most of your code in the AppDeligate is certainly bad practice and will lead to horrible code as things get more complex and need to be maintained.
This question has been on my mind ever since I started with iOS development: the UINavigationController and the usage of memory.
I see lots of apps like iMail, Find Friends, Notes, etc. where the UINavigationController makes perfect sense. They allow you to drill down two or three levels of hierarchy and that's it.
But imagine browsing a deep hierarchy, like your Mac's file system, starting from the root folder.
If I used a UINavigationController, I would keep on pushing hundreds of controllers on the stack (worst case). I don't consider that a good usage. There can be cases where the pushed controllers can become very heavy (as far as memory is concerned) and they just sit there for nothing.
I would wish there was a "dynamic" version of the UINavigationController: it would just tell you what to create when navigating back up the hierarchy instead of just popping up the hierarchy.
My question is now: is UINavigationController meant to be used for deep hierarchies? What are good alternatives if you want all the animation, bar items, etc?
Or do I see issues where there aren't any?
UINavigationController is dynamic. When you get low on memory, you can release the memory used by parts of the hierarchy that are not visible -- this is a manual step when you get a low memory notifiction -- and the OS automatically releases the views in the same situation.
When the top view controller is popped off the stack, your viewDidLoad method would be called, allowing you to recreate your view.
If it really is a problem, iOS5 allows you to create your own "container" views, so you could create your own navigation controller that does exactly as you suggest. Check out the "Implementing a Container View Controller" section of the UIViewController documentation.
Having said that, you might need to add some shortcuts to work your way around a very deep hierarchy. The UI could get painful if you can only go back one screen at a time.
Is there disadvantages to using WebKit WebViews compared to using NSViews?
I'm using a webview to create a UI for an application. The application itself does not have much interactivity. I have seen it mentioned, on this website & others, that using a WebView can be convient means of prototyping.
However, with our team this seems like an ideal way to produce the production ready UIs, especially with WebKit. Are we missing something?
Thanks,
Ross
Okay, so you seem to be asking if using an HTML interface (presented via a WebView) for your application has any disadvantages.
The answer to this is "no", at least "not necessarily". This is analogous to building an iPhone specific web application, and there are some excellent examples of those. The caveat would be that a lot of those sites end up recreating the look and feel of a native iPhone app, for consistency and to make the users feel "at home".
Given that you're developing a native app anyway, it seems a shame to throw away, or recreate, the responsiveness and appearance of the native chrome. Of course, for certain types of applications (games are an obvious example) a user has no expectations about the application's UI, so you're free to knock yourself out.
The other factor to consider is the amount of interactivity (although I notice that you say there isn't much in your case). The native controls will make coding a lot simpler than having to capture all user input through the "filter" of a WebView, even though using one might make the initial layout of the screens easier.
I hope that's the sort of answer you were looking for (although it's mostly non technical).
As you might have known if you spend some time in the documentation, you'd have seem that WebView is a subclass of NSView.
The documentation says about WebView:
WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes. To embed web content in your application, you just create a WebView object, attach it to a window, and send a loadRequest: message to its main frame.
And about NSView:
NSView is a class that defines the basic drawing, event-handling, and printing architecture of an application. You typically don’t interact with the NSView API directly; rather, your custom view classes inherit from NSView and override many of its methods, which are invoked automatically by the Application Kit. If you’re not creating a custom view class, there are few methods you need to use.
So here's the answer to your question:
Is there disadvantages to using WebKit WebViews compared to using NSViews?
Yes. You can't display any web content with NSView. That's what you need WebView for.
I suggest reading some more documentation though.