Undeclared identifer error in prepareForSegue : using Storyboards in iOS6 - objective-c

I am trying to build a 2 scene application using Storyboards in iOS6.
I am taking the users name via text input in the first scene and passing it using a push segue to the second scene; where it is displayed in a label.
The first scene's UIViewController is called ViewController and the second scenes UIViewcontroller is DrawViewController.
I have imported the the DrawViewController.h in my ViewController.m file where I have defined the prepareForSegue as below:
-(void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender{
if ([segue.identifier isEqualToString:#"ColorPickerControllerSegue"]){
DrawViewController *dvc =[segue destinationViewController];
dvc.userName= self.userName;
}
}
Here userName is a NSString defined in DrawViewController.
I am getting "use of undeclared identifer:DrawViewController".
I am quite new to iOS programming, so is there something I am missing here?
I have set the second view controller's custom class to DrawViewController.

I was able to solve this issue by removing the existing DrawViewController.h and DrawViewController.m files and then creating and adding them back to the the project.
It seemed to do the trick.

Related

Replace PlaceHolder View With other ViewControllers leads to Thread 1:EXC_BAD_ACCESS Code 1

hey guys created a custom segue tab bar, using this guys tutorial,
http://www.scott-sherwood.com/tutorial/ios-5-creating-a-custom-side-tabbar-using-storyboards-and-custom-segues/
after trying to figure out why why my app doesn't work, i realised that the technique i was using was about replacing the existing view with the linked ViewController as a subview.
////////////////////////////////////////// the over-written perform method as follows /////////////////////////
-(void) perform {
ViewController *src = (ViewController *)[self sourceViewController];
UIViewController *dst = (UIViewController *) self.destinationViewController;
for (UIView *view in src.placeholderView.subviews ) {
[view removeFromSuperview];
}
src.currentViewController = dst;
[src.placeholderView addSubview:dst.view]; }
////////////////////////////////////////////// /////////////////////// /////////////////////// ///////////////////////
now once i am on the linked ViewControllers i was hoping to add another link to another ViewController which would hold the Editing functions for the information each respective pervious ViewControllers. Now when i try to connect a the ViewControllers via any Segue the app crashes and give me a Thread 1:EXC_BAD_ACCESS. When i use NSZombie its give me this in the console,
[UIStoryboardSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x7c3a4d20
no i understand what is happening in theory, the viewController is trying to ad the next one to an empty space (i think the entire placeHolder has been deleted thus giving the viewController nowhere to go) i think, i was wondering if anyone could help with this i mean i a have been looking everywhere for a solution but i keep getting the same error.
i even created a VieController class for the ProfileViewController.m/ProfileViewController.h in which i add
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"ProfileEditSegue"]){
ProfileViewController *cvc = (ProfileViewController *)[segue destinationViewController];
[cvc.placeholderView addSubview:cvc.view];
}
}
this to leads me to the same errors. I will be glad to send anyone my source files, the same error occurs when i do it on the supplied files from the tutorial.
PS. i am using this method so that i can have a vertical navigation bar, but i want to do it simply so i could also learn how one works and be able to use/develope it further.
any help would be great
The problem wasnt in those methods it was because the currentViewController instances was set to weak instead of strong

Confusion with UINavigationControllers in SplitViewController

I am setting up an iPad app that uses a SplitViewController. In my app delegate I have the following in didFinishLaunchingWithOptions:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *leftNavController = [splitViewController.viewControllers objectAtIndex:0];
LeftViewController *leftViewController = (LeftViewController*)[leftNavController topViewController];
DetailViewController *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
NSLog(#"Detail View Ctrl >> %#", [detailViewController class]);
When I run the app, the NSLog statement returns "UINavigationController" when DetailViewController is actually a subclass of UIViewController. However, in XCode, code completion shows all the methods that are implemented in the DetailViewController subclass. Any ideas? Thanks!
I think your DetailViewController is actually embedded inside a UINavigationController, and your fourth line is in error. Take a look instead at the topViewController for the second view controller inside your split view controller, much like you do for the LeftViewController.
The reason Xcode is continuing to suggest completion for DetailViewController methods is because you've given it that type. Code completion doesn't rely on runtime behavior (how could it?) – instead, it relies on static analysis of the code that you type. If you tell Xcode that something is a DetailViewController, it'll believe you and autocomplete based on that information.

UIViewController throwing unrecognized selector exception on prepareForSegue

I'm trying to follow along the Stanford CS193p iOS programing lectures. One of the demo programs, called "Happiness" creates two UIViewControllers, a "PsychViewController" and a "HappinessViewController." It segues from the PsychViewController to the HappinessViewController using a target action method.
The following code keeps throwing this exception: "-[UIViewController setHappiness:]: unrecognized selector sent to instance"
Here's the offending code:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"ShowDiagnosis"]) {
[segue.destinationViewController setHappiness:7];
}
}
I have searched this site and others, and the usually when this error comes up, it is because the generic UIViewController has not been correctly set to the specific view controller object used in the program, in this case the "HappinessViewController." But I have set the generic UIViewController to be a HappinessViewController using the identity inspector in IB, and I am still getting the exception. I am tearing my hair out, if anyone could help it would be much appreciated.
Let's look at the exception:
-[UIViewController setHappiness:]: unrecognized selector sent to instance
This tells you two things about the message that was unrecognized. It tells you the selector, setHappiness:. It also tells you the actual, runtime class of the receiver, UIViewController.
Of course, UIViewController has no method named setHappiness:. That's why you got the exception.
You wrote a subclass of UIViewController called HappinessViewController which does have a setHappiness: method (or a read/write property named happiness, which generates the method). And you intended for the receiver (the destination view controller) to be an instance of that subclass (HappinessViewController).
But the exception is telling you that the destination view controller is just a plain UIViewController. So even though you think you did, you probably did not set the view controller's custom class in the storyboard. Maybe you set the custom class of some other view controller, but you didn't set the class of this segue's destination.
You need to set the destination view controller's custom class in the Identity Inspector, like this:
I figured out the problem. Although I had correctly specified that the relevant UIViewController was a HappinessViewController, the linker, was for some reason, not linking to the correct files. The fix was to go to double click on the .xcodeproj file inside Xcode, then go to Build Phases and manually add the files under "Compile Sources."
For me changing the class of the view controller in the story board worked.
Try like this:
HappinessViewController *controller = segue.destinationViewController;
[controller setHappiness:7];
I had the same problem today and it was because my custom class was in a library. The library itself was being linked in build phases, but that in itself was not enough to pull in the class. So finally I solved it by add the following line to my AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[ CustomClass class ];
}
This forces the linker to pull in the class. Otherwise simply linking in the library may not be enough to pull in the class unless it is referenced somewhere in the application.
I tried adding a Cast and it worked for me, I had the same problem:
FirstViewController *detailViewController =
(FirstViewController *)[segue destinationViewController];
Check which prepareForSegue is triggering. My problem was that 2 segues were triggering, in the current viewController and in the incoming viewController. The solution, and always a good practice is to check segues identifiers.
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"segueIdentifier"]) {
}
}
Cast before assigning
HappinessViewController *controller = (HappinessViewController *)segue.destinationViewController;
[controller setHappiness:7];
Make sure in your storyboard, HappinessViewController is set as the class of you VC

textFieldShouldReturn not firing in iPad app

I have an iPad app created using XCode 4 with Storyboard. I have a UITableViewController with the interface defined as such:
#interface CustomerViewController : UITableViewController <UITextFieldDelegate>
In the .m file, I have a code snippet as:
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
if(textField == businessName) {
[email becomeFirstResponder];
return true;
}
The method 'textFieldShouldReturn' does NOT get executed. What else needs to be done? (BTW... I have never been able to get this to work in a iPad app, but always successful in a iPhone app)
In the textFieldShouldReturn method, you're testing if the textField is equal to businessName. I'm assuming that's a UITextField object, but you have to set the delegate to receive callbacks. Just a simple self.businessName.delegate = self; when you create the TextField.
Another tip, I'd recommend calling it something like businessNameTextField. It's easier to read throughout your code.
You have to set the view controller as the delegate of the text field, just declaring that you conform to the protocol isn't enough. If it works in the iPhone but not iPad, then the chances are you haven't linked the delegate outlet in the iPad storyboard, but you have in the iPhone.

iOS 5 page curl with custom View Controller

I am trying to use page curl to show a sub page using Xcode storyboards. Everything is working when I have the sub page as UIViewController, but when I change it to a custom UIViewController, the sub page is black. Happens both on device and simulator.
iOS 5
Xcode Version 4.2
Anyone seen this before?
Edit: This is happening every time when using a custom UIViewController, no matter if I use push or model. If I use a custom UITableViewController it is fine.
I have in my ViewController which starts the transition this method:
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender{
NSLog(#"prepare segue modal.partial_curl");
if([[segue identifier] isEqualToString: #"sample"]){
"setgoalviewcontrollerobjecthere" = [segue destinationViewController];
}
}
don't forget to import .h file, alloc and init. name segue identifier in storyboard file "sample", and pick style modal, transition partial curl. easiest way works every time. If you do it just programmatically you have to do a lot more -> google
domink