OCUnit testing problems in UINavigationController - iphone

I create single view application with 1) Story board 2) ARC and 3) Unit Testing.
In view controller i drag on UIButton. and ViewContrller embedded with Navigation Controller (Using Interface).
It run fine in when i simply run the application, But when i run the application test case target then it aries problem.
vc is ViewController Object which i declare in .h file. and createPDFBtn is the object of UIButton.
Which thing i missing?

You are trying to call createPDFBtn on your view controller (self.vc). Since you do not have a method with this name you get an error message:
unrecognized selector sent to instance
Three possible problems and their solutions:
You may be calling the method on the wrong object - is vc your right object?
vc is correct but you do not have the createPDFBtn method implemented - implement the method.
you have implementet createPDFBtn in your vc object - is it a public or a private method? Is it in your .h file ?

Related

Call function in another ViewController (macOS)

How can I communicate with another View Controller on Xcode Storyboards in any possible way?
Given the principle of encapsulation, the preferred way seems to be to call a function in the other ViewController.
(failed) ideas:
Using self.storyboard to instantiate a Controller with the specified Identifier, casting it to the correct View Controller subclass
instantiating the view controller with let c = specialViewController() [doesn't work because the instance's views haven't loaded]
connecting an IBOutlet to another NSViewController subclass [this one should work but doesn't]
Note: iOS solutions often are not the same as MacOS solutions
First failed idea code:
let spec_ref = self.storyboard!.instantiateController(withIdentifier: "specialSettings") as! SpecialSettings
spec_ref.save_spec_settings();
save_spec_function:
The spec_ref still cannot access IBOutlets in the other ViewController on the Storyboard, so it must not be the correct instance.

instantiateViewControllerWithIdentifier crashes app

I am trying to instantiate a ViewController defined in MainStoryBoard.storyboard using the code snippet shown in the pic below. I also assigned an identifier to the controller but app crashed with the error shown in pic saying "Storyboard doesn't contain a controller with identifier masterViewController" although you can clearly see in pic that its there.
Any help will be appreciated.
Just so you know, following solution didn't work for me: Crash with instantiateViewControllerWithIdentifier
Below is the snapshot that confirms that the storyboard object is same that is retrieved from viewcontroller and used to instantiateViewControllerWithIdentifer:.
SITUATION DESCRIPTION: I am trying to develop a custom SplitViewController (subclassed from UIViewController). This UIViewController is purely programmatic i.e. not based on IBInterface layout. However for its children i.e MasterViewController and DetailViewController I have made layouts in IBInterface. Now I am retrieving a UIStoryboard object in SplitViewController (purely programatic one) and passing it to a utility class shown here in the first pic that uses it to instantiate MasterViewController based on a layout in the Storyboard.
Hm, looks like if should work.
Try this:
Clean project and rebuild
Check if storyboard contains an instance of the correct storyboard
Fix by shaffooo (from comments below)
I rebuilt my storyboard and it fixed the issue I was having.
try to write the same name of your ViewController class into 'StoryBoard ID' in IB. Then edit the argument of your instantiateViewControllerWithIdentifier method with same string:
yourVCName *startingViewController = (yourVCName *)[self.storyboard instantiateViewControllerWithIdentifier:#"yourVCName"];

Sending data from a delegate to a view controller in Objective-C on an iPhone

Note: I've only been using Objective-C for a week.
Here's my end goal: I want to call out to a server and grab a json file that has urls and url descriptions in it. If I can't get that file, I want to show an error view. If I can get that file, I want to display its contents in a table view.
Restrictions: I'm doing this in a Cocoa Touch Static Library (by requirement) to be included in a larger app that will load it "like" an app.
What I'm doing right now is I'm using Reachability to check for a connection to the host. Then I'm opening an NSURLConnection for the file. Once the file is gotten, I parse the json using the json-framework. The datatype of the jsonObject is id (afaik that means *).
Currently, ALL of that is happening in the Delegate. If I get errors with connection or file retrieval, I set the rootView to the error view controller. Otherwise, I set the rootView to my other view.
I've tried the method of setting the jsonObject to extern in the view controller, but that didn't work. I tried setting a property in the view controller and setting the jsonObject in the controller after I create it, but the jsonObject is nil at that point and everything blows up with some error regarding incorrect selectors or something.
Am I even headed in the right direction with this? How SHOULD this be done?
EDIT
My view controller is typed as UINavigationController and I stick whichever view controller I end up using into it. When I try to call a setter in my view controller, I have to cast the UINavigationController to my view type to be able to see the setter, but when I run it, I get the following error:
SpringboardApplication[5850:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setJsonObject:]: unrecognized selector sent to instance 0x602ed20'
I am calling it as follows:
[(LU_SOCLINKS_RootViewController *) root_navigation_controller setJsonObject:jsonObject];
By "delegate" you mean the app delegate? I assume that the view controller is in an instance variable in your app delegate, in which case you just need to create a setter method in the view controller that you can use to pass the data.
In the view controller:
.h
- (void)setData:(NSData/NSString/whatever *)data;
.m
- (void)setData:(NSData/NSString/whatever *)data {
vcData = [data retain];
// do stuff with the data
}
In the app delegate
[viewController setData:theData];
This is a simplistic answer. Am I understanding your problem correctly?

Building Login onto already existing app

I am building a login onto an completed app. The app have already used the appdelegate but in order to do the login, it needs to use the appdelegate. I am stuck at a point where I cannot "make a new reference outlet for your Navigation Controller to your App Delegate." since the appdelegate in not in my .xib.
How can I make the appdelegate appear on the .xib file so I can link it with the navigation controller?
Thanks.
We need to first understand the architecture of your app. But even without that, one solution that I could think of is this.
Create a viewController named ValidateViewController by right clicking on your project-> add new file -> UIViewControllerSubClass and check the xib option as well.
This will generate the following
ValidateViewController.h
ValidateViewController.m
ValidateViewController.xib
Write all your validations functions in this class. Write a function in this class that would return true on validation success and false on validation failure. Now let's use this class in your appdelegate.
Now in your appdelegate.h, import this ValidateViewController.h. All the validation functions that you defined in the ValidateViewController will now be exposed to be used just by creating and allocating an object of ValidateViewController in your appdelegate. I hope this is pretty straight forward for you. If not, we can look at it again.
Now in the applicationDidFinishLaunching method of your appdelegate, the first thing you do is you load this ValidateViewController as a modalView controller programmatically. Once loaded, call the functions and get the return values from your validate functions, if validation succeeds, dismiss this modalViewController otherwise, you pop up an alertView in the modalViewController saying, validation was unsuccessful and the user stays on the ValidationViewController. I think that should solve your problem. If you need more help please come back. If you find the answer satisfactory, please accept it.

Passing info to a delegate from a UIActionSheet

My understanding about passing data back to a delegate completely revolves around making a new view controller and having it conform to a protocol.
I am trying to get a time input back from a UIDatePicker set with the UIDatePickerModeCountDownTimer mode and I am running into issues.
Inside of Main1.m I create a UIActionSheet *action, and set everything up so that it presents itself with a UIDatePicker on a click. Inside of Main.m I also say:
main.delegate = self;
If this were not a UIActionSheet, I would make a protocol reference inside the new ViewController and then have the new vc pass data to a method that Main has, but I can't do that with a UIActionSheet!!
What am I missing? I assume there is something inherently different about Action Sheets, ut I can't figure it out.
Thanks for your help!!!
EDIT:
Sorry! I was giving a generic name to my view controller. It isn't actually Main.m, its FirstViewController.h/m
I didn't realize that my generic reference was getting mixed up with the Main.m file that is completely different than a vc.
I don't exactly understand why you're putting your delegate assignment in Main.m. I assume that you're setting up your UIActionSheet in a ViewController, and launching it from there. In this case, your ViewController is your delegate object. So you need to make sure that your ViewController implements the UIActionSheetDelegate. ie:
#interface SomeController : UIViewController <UIActionSheetDelegate>
Then you simply implement the required methods of that delegate in your view controller class, and that should do it. If I'm missing something about how you're implementing this, then you need to provide more code examples to examine.