Adding a back button to table view with embedded Navigation Controller Xcode - xcode

Here is the flow of my app so far.
View controller (HOME) with rect button (modal) linking to > Table view controller with an embedded navigation controller linked to> Multiple View controllers with an image on each.
This work perfectly s but......
I want to have a "back" button on my Table view controller to take me back to my (HOME) View controller.
I am new to this and have tried to find relevant info and tried loads of options but noting seems to work and although i can see a button in the simulator (and have Modal linked it to my (HOME) view ) the simulator crashes every time and this error message appears.....
*2013-01-05 17:19:40.080 MASTER DETAIL POLAR TEST[10975:f803] -[HomeController setCharacterNumber:]: unrecognized selector sent to instance 0x6894620
2013-01-05 17:19:40.084 MASTER DETAIL POLAR TEST[10975:f803] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeController setCharacterNumber:]: unrecognized selector sent to instance 0x6894620'**
Please Help.....

may it would be the best your HOME viewController is embedded in the navigationController an become RootViewController. By clicking the rect-button the tableViewController will appear.
Use the navigationControllers method – pushViewController:animated: or create a new segue an select "push".
If you don't like this way you have to add a navigationBarButtonItem to the navigationBar. Link this button item to an action which send the message dismissViewControllerAnimated:completion: to the tableViewController. This should work.

Related

keyDown(with:) Not Called on Custom ViewController or View, Only WindowController

I have moved most of the core functionality of my non-document based macOS app to a custom, embedded framework.
The app code has a standard main storyboard with an initial window, and the window has a "window content" relationship/segue into a storyboard reference pointing to a storyboard inside the embedded framework. Therein lies a custom NSViewController subclass and a custom NSView subclass.
I want to group all the input event handling code inside the framework, which means implementing mouseDown(with:) on the custom NSView subclass, and --lo and behold-- it gets called when I click inside the app window. So far, so good.
Next, I implemented keyDown(with:) to similarly handle keyboard input. However, at runtime, it does not get called and instead, I hear the annoying beep (NSBeep).
I tried implementing keyDown(with:) on the view controller instead, but it's all the same.
Finally, I tried implementing the key handler on my NSWindowController subclass instead, and that does work.
So I could get around this by forwarding the event like so:
class WindowController: NSWindowController {
override func keyDown(with event: NSEvent) {
contentViewController?.view.keyDown(with: event)
}
}
, but it is very inelegant. I would prefer to not pollute the app code with input logic.
This doesn't seem to have anything to do with embedding frameworks, however. I put together a minimal project from the 'Cocoa App' template and confirmed that indeed keyDown(with:) only gets called if implemented on the window controller code, but not on the view or view controller side.
How can I get keyDown(with:) to be called on the view or view controller (not the window or window controller) in a storyboard-based app? (so I can move it from the main app to my embedded framework).
Edit: The question has been marked as duplicate. I tried the solutions pointed in answers to the other question (namely, override acceptsFirstResponder to return true). This solves the problem in my minimal demo project, but when I tried it on my full app, it still does not work (I did see that question and did try to override acceptsFirstResponder in my app before posting this question).
I will now try to modify my minimal poeject to see if I can reporduce the issue in the main app.
Edit 2: I have refactored the minimal project to:
Send the view controller to a separate storyboard,
Send the view controller's storyboard and represented classes (custom view, custom view controller) to a separate, embedded framework.
Now the basic setup mirrors that of my app in all that seems to matter, but still can not reproduce the issue in the minimal project. I will investiate further...
Edit 3: I haven't been able to reproduce the issue on the minimal project.
On my app's custom view, I implemented:
public override var acceptsFirstResponder: Bool {
return true
}
public override func performKeyEquivalent(with event: NSEvent) -> Bool {
let retVal = super.performKeyEquivalent(with: event)
return retVal
}
On startup, acceptsFirstResponder is called twice.
When hitting any key, performKeyEquivalent(with:) is called twice, too. Inspectig the intermediate variable retVal above reveals that the super class's implementation always returns false. After returning from this method, NSBeep() is called and keyDown(with:) isn't.
If instead of super.performKeyEquivalent(with:) I force-return true, I can avert the call to NSBeep() (but keyDown(with:) is still not called...)
Edit 4 (Final):
Out of desperation, I cleared the "Custom Class" field of the window controller's Identity Inspector in my app's main storyboard (to the default NSWindowController).
Suddenly, my custom view's keyDown(with:) starts getting called.
I reinstated the custom class to confirm.
It still works.
I clean the build folder and try again.
It still works.
Now I can no longer reproduce the issue even on my main app. I really don't know what to say...

How do I connect my Navigation Controller to every screen of my storyboard?

I am using Swift and Xcode 6.1.1, I used a navigation controller in my story board and set it as the initial view. I have a sign up screen and a login screen and I use buttons to navigate with segues between them. After the user logs in I segue to the main app view but how would I do this using my navigation controller.
In my app delegate didFinishLoadingWithOptions is create a var navController = UINavigationController() but how do I let this variable connect with the navigation controller in my Storyboard. I want to be able to set new views as the root view once an action has succeeded like a successful login.
I am still learning alot about iOS development please explain like I am a 5 year old.
you don't have to manual create a UINavigationController in "app delegate".
as you said,you have edit "initial view controller" setting in "Interface builder" already! so when the app startup,the "initial view controller"(also UINavigationController,as you set) is created automatic!
All you have to do is create a relationship bettween the first UINavigationController(login view) with another UIViewController(login sucess view).
How to do this?
Just hold "control" key and from "UINavigationController" drag a blue line to the "login sucess UIViewController",and select "init root viewcontroller" in "releationship segue" section at the popmenu!
you can read this article for more detail
enter storyboards-tutorial-in-ios-7-part-1

Mac os x main window controller

When I create a cocoa based mac osx application in xcode. I get a default class AppDelegate which is sublcass of NSObject < NSApplicationDelegate >
The application is one main window which has some buttons , tableview etc,
My question is should I make this AppDelegate class to be the controller of my main window ? or should I create a new controller. Under what condition should I choose my delegate to be the controller and when should I not ?
If the application is not some throwaway test application you should create a new controller and put there logic for the view. If the application starts to grow you may need even more controllers and views e.g. Status bar could be separate view with a separate controller.
In the AppDelegate you should put only the things that are specific for the complete application like menu, starting, stopping etc.

UILocalNotification and alertLaunchImage

Hmmm……
A question about UILocalNotification and the notificaton's alertLaunchImage.
My app uses UILocalNotifiaction(s) to get users' attention. As usual, an alert is presented with "Action" and "Close" buttons. When the user taps Action, the image specified by alertLaunchImage is presented. The alertLaunchImage is a screenshot of of one of the views of the app which is shown after the data is initialized when launched normally.
Here are the 3 cases when the notification is delivered:
App is running in foreground - no alert, no launchImage is shown as designed. No problems.
If my app is running in background when the notification is delivered, the launchImage works like a charm. No problems. The launchImage with no app-related data is shown and then the app fills up the data. This part works seamlessly.
However, if the app is not running when the notification is delivered, the sequence is confusing - or I missed something. The app gets launched and shows the alertLaunchImage instead of the Default image. Then is goes thru several other screens (as part of initialization and data processing) before the actual screen (live version of alertLaunchImage) is shown.
This can get very confusing to the user. My question comes in here. How can this be avoided?
R/-
Sam.!
you can try cleaning up the alert view settings in applicationWillTerminate:
According to the UIApplicationDelegate reference applicationWillTerminate::
"This method lets your application know
that it is about to be terminated and
purged from memory entirely. You
should use this method to perform any
final clean-up tasks for your
application, such as freeing shared
resources, saving user data,
invalidating timers, and storing
enough application state to
reconstitute your application’s
interface when it is relaunched"
HTH,
Oded
If your app is launched by a local notification, you will receive that notification in the options passed to -application:didFinishLaunchingWithOptions:. Based on that, you can write code that navigates to the correct screen without animations.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification != nil) {
// startup by local notification
} else {
// normal startup
}
}

SIGBART NSInternalInconsistencyException attempting transition while transition in progress

I'm extending Appirater (a stand alone class that presents an UIAlertView to the user to solicit a rating for your app) by adding a single button that when selected will dismiss the alert, and bring up MFMailComposerViewController so the user can email feedback.
My implementation was/is to post a notification in Appirater, and then using [self presentModalViewController: vc animated: YES] from a viewController that listens for the notification. That viewController is the super class of all my main viewControllers.
It works in one of the main viewControllers is up, but crash's from within other viewControllers are the current viewController and I see the following warning in the console:
2010-12-17 11:27:59.632
Wine.com[18514:207] * Terminating
app due to uncaught exception
'NSInternalInconsistencyException',
reason: 'Attempting to begin a modal
transition from to
while a transition is
already in progress. Wait for
viewDidAppear/viewDidDisappear to know
the current transition has completed'
I tried delaying the sending of the notification from Appirater, but that does not seem to help.
Ideas/pointers?
I had a similar error when clicking on a UIButton to open a Modal View. I changed the UIButton's listener from UIControlEventAllEvents to UIControlEventTouchUpInside. Basically, it was firing the Modal View on Touch Down Inside and then trying to create another instance of the Modal View on Touch Up Inside.
The problem was that by implementing this in a superclass, I needed to make sure only the currently active viewController was processing the notification, not ALL 5 of them.

Resources