XCode 7 Date picker cause crash of application - ios

Hi I need to integrate date picker with inputView, I am on Xcode7. Using below code the application cause exception. The exception happening while I am touching UITextField element.
Here is the relevant part of the code where the date picker used.
#property (weak, nonatomic) IBOutlet UIDatePicker *graphDate;
#property (weak, nonatomic) IBOutlet UITextField *fromdate;
#property (weak, nonatomic) IBOutlet UITextField *toDate;
............................................................
..............................................................
[_graphDate setDatePickerMode:UIDatePickerModeDateAndTime];
............................................................
..............................................................
[_graphDate setHidden:TRUE];
[_graphDate setFrame:CGRectMake(600, 600, 400, 162)];
_toDate.inputView = _graphDate;
_fromdate.inputView = _graphDate;
_graphDate.date = [NSDate date];
The exception message,
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason:
'child view controller:<UICompatibilityInputViewController: 0x80286850>
should have parent view controller:<VALiveViewController: 0x7cbeda00>
but requested parent is:<UIInputWindowController: 0x7cc25a00>'
I already refereed the answer here UIViewControllerHierarchyInconsistency in 64 bit iOS device but no idea how to apply here, I am newbie in IOS.
Any help will be appreciated.
Thanks,
Haris

Related

How to have a single IB Outlet for 2 UIViews

I'm currently developing an application that displays ads. The main view controller has 2 UIViews that act as containers for the ad views that will be passed in when they are loaded. However, I'm using an API that only takes a single "adContainer" as a parameter, so tried using an IBOutlet Collection called adContainer that has each of these 2 UIViews (adContainer1 and adContainer2) linked to it. I tagged each of these so that on the main view controller when I try to load an ad, I can iterate through the adContainers in the IBOutlet Collection and request each adContainer individually based on the object's tag. I'm being thrown this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance
Here is the code for my viewController.h :
#import <UIKit/UIKit.h>
#import "MPAdView.h"
#import "MPViewController.h"
#class MPAdInfo;
#interface MPSmaatoScrollBannerAdDetailViewController :
UIViewController <MPAdViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *titleLabel;
#property (weak, nonatomic) IBOutlet UILabel *IDLabel;
#property (weak, nonatomic) IBOutlet UILabel *failLabel;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *spinner;
#property (strong, nonatomic) IBOutletCollection(UIView) NSArray
*adViewContainer;
- (id)initWithAdInfo:(MPAdInfo *)info;
#end
And here is the function in my viewController.m that I suspect is throwing the error:
- (void)configureAd
{
for (UIView *ad in _adViewContainer) {
if (ad.tag == 1) {
self.adView1 = [[MPSampleAppInstanceProvider sharedProvider] buildMPAdViewWithAdUnitID:self.info.ID
size:ad.bounds.size];
self.adView1.delegate = self;
self.adView1.accessibilityLabel = #"smaato banner";
self.adView1.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[ad addSubview:self.adView1];
[self.adView1 stopAutomaticallyRefreshingContents];
} else if (ad.tag == 2) {
self.adView2 = [[MPSampleAppInstanceProvider sharedProvider] buildMPAdViewWithAdUnitID:self.info.ID
size:ad.bounds.size];
self.adView2.delegate = self;
self.adView2.accessibilityLabel = #"smaato banner";
self.adView2.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[ad addSubview:self.adView2];
[self.adView2 stopAutomaticallyRefreshingContents];
}
}
}
Please help! Thank you in advance!
According to the way you said, I did not report an error myself; it may be that your xib cable is not set correctly.
You can refer to this:
"countByEnumeratingWithState:objects:count:" Error

This class is not key value coding-compliant for the key Picker

I added a view to my app that I open from a button and can't find what I'm doing wrong.
I triple checked that dataSource & delegate are connected to File's Owner
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HelpViewController 0xab58980> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Picker.'
The code in my viewcontroller.h
#interface LanguageSelectionViewController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIPickerView *Picker;
NSArray *PickerData;
}
#property (retain, nonatomic) IBOutlet UIPickerView *Picker;
#property (retain, nonatomic) NSArray *PickerData;
#end
Anyone got a solution or a tip in the right direction?
Go to your storyboard click the helpviewcontroller (the whole thing so you have a blue outline around the view) now with the utility toolbar (toolbar on the right) click the arrow (the right most icon) you should see a ! mark on one of the connections. Delete that and it should work.

Terminating app due to uncaught exception 'NSUnknownKeyException [duplicate]

This question already has an answer here:
Terminating app due to uncaught exception 'NSUnknownKeyException' - error [duplicate]
(1 answer)
Closed 9 years ago.
I am coding some dummy apps to get an understanding for iOS this one such app is a TODO list. I get the following error when I click the button to add a new task.
2013-06-20 09:56:00.763 SnapTask[2322:11303] Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SLAddTaskViewController 0x917fb90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key email.'
First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1afb1 0xb7c711 0xafdec8 0xafd9b7 0xb28428 0x2340cc 0x10e3663 0x1c8d45a 0x232bcf 0xf7e37 0xf8418 0x24634e 0xf8648 0xf8882 0xf8b2a 0x10fef5 0x10ffdb 0x110286 0x110381 0x110eab 0x110fc9 0x10e225 0x126082 0x12613a 0x3050e6 0xd6cba 0xd7ae8 0x304f44 0x3044eb 0x1014f3 0x101777 0x1017b7 0x46cfe2 0x45ead9 0x45eb54 0x10e3705 0x1a920 0x256b24 0x10e3705 0x1a920 0x1a8b8 0xdb671 0xdbbcf 0xdad38 0x4a33f 0x4a552 0x283aa 0x19cf8 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x1765c 0x24ad 0x23d5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
I have no idea where to even start, the list stores names emails and etc when adding a task
This is my AddTaskViewController header
#import <UIKit/UIKit.h>
#class TaskListViewController;
#interface AddTaskViewController : UITableViewController
-(IBAction)cancelButtonPressed:(id)sender;
-(IBAction)doneButtonPressed:(id)sender;
#property (nonatomic,strong) IBOutlet UITextView *nameField;
#property (nonatomic,strong) IBOutlet UITextView *emailField;
#property (nonatomic,strong) IBOutlet UITextView *homeField;
#property (nonatomic,strong) IBOutlet UITextView *cellField;
#property (nonatomic,strong) IBOutlet UITextView *addressField;
#property (nonatomic,strong) IBOutlet UITextView *notesField;
#property (nonatomic,strong) IBOutlet UITextView *dateField;
#property (nonatomic,strong) IBOutlet TaskListViewController * taskListViewController;
#end
Thank you I am so confused :(
I think you have changed your IBOutlet Name email to emailField.So you need to reconnect your IBOutlet in your xib.So please click on File's Owners control+left click at that time you will see different color on your connectivity.So reconnect you IBOutlet.
I hope it will be helpful.
Try reconnecting all your UIElements in that class.

IBOutlets deallocated after modal view controller

I have a couple of IBOutlets in my ViewController class, declared like this:
#property (nonatomic, retain) IBOutlet UILabel* labelHostStatus;
#property (nonatomic, retain) IBOutlet UIButton* connectButton;
#property (nonatomic, retain) IBOutlet UITextField* fieldAddress;
#property (nonatomic, retain) IBOutlet UITextField* fieldPort;
(and of course #synthesize'd)
Everything is working great, and I can access the IBOutlets in code, and get/set texts and stuff.
At some point I decide to present a modal view controller, which goes OK. However, after dismissing the modal view controller and coming back to the main controller, I can't seem to access the above mentioned outlets anymore. I get excepctions and crashes when trying to do so:
2013-05-13 22:39:47.359 [7267:c07] -[__NSCFString text]: unrecognized selector sent to instance 0x885aa30
Whats wrong? :(
Oh my, nevermind. Just figured I've released the parent view in the modal view controller class after it's been dismissed. D'oh!

Set title of a button there is selected from an array - Xcode iOS

I have a lot of buttons that i would like to give a title when the view is loaded.
The title of the buttons varies depending on what day of the month it is. Therefore I have created an array with the name of all the buttons. My code is as follows:
My interface:
#property (strong, nonatomic) IBOutlet UIButton *button1;
#property (strong, nonatomic) IBOutlet UIButton *button2;
#property (strong, nonatomic) IBOutlet UIButton *button3;
#property (strong, nonatomic) IBOutlet UIButton *button4;
#property (strong, nonatomic) IBOutlet UIButton *button5;
#property (strong, nonatomic) IBOutlet UIButton *button6;
#property (strong, nonatomic) IBOutlet UIButton *button7;
#property (strong, nonatomic) IBOutlet UIButton *button8;
#property (strong, nonatomic) IBOutlet UIButton *button9;
#property (strong, nonatomic) IBOutlet UIButton *button10;
My implementation:
#synthesize button1 = _button1;
#synthesize button2 = _button2;
#synthesize button3 = _button3;
#synthesize button4 = _button4;
#synthesize button5 = _button5;
#synthesize button6 = _button6;
#synthesize button7 = _button7;
#synthesize button8 = _button8;
#synthesize button9 = _button9;
#synthesize button10 = _button10;
NSArray *myArray = [NSArray arrayWithObjects: #"dummyButton", #"_button1", #"_button2", #"_button3", #"_button4", #"_button5", #"_button6", #"_button7", #"_button8", #"_button9", #"_button10", nil];
for (int i = varDefinedEarlier; i<=totalAmountOfNeededTitles; i++) {
NSString *theTitleSting = [NSString stringWithFormat:#"%i",i];
NSLog(#"arrayValue:%#", [myArray objectAtIndex:i]); //Works prints the button name (for example _button7)
[[myArray objectAtIndex:i] setTitle:theTitleSting forState:UIControlStateNormal];
//The line above is where the app crashes. Everything else works just fine.
}
The error provided to me is a "Thread 1: signal SIGABRT
Besides that, this is what the log says:
-[__NSCFConstantString setTitle:forState:]: unrecognized selector sent to instance 0x14a48
2012-07-10 22:57:49.649 Don't Break the Chain[10302:707] * * * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString setTitle:forState:]: unrecognized selector sent to instance 0x14a48'
* * * First throw call stack:
(0x3774788f 0x3544c259 0x3774aa9b 0x37749915 0x376a4650 0xdc2f 0x31454c8b 0x314611e9 0x31461059 0x31460f3f 0x3146070b 0x31460503 0x31454aff 0x314547d5 0x314cd903 0x31547627 0x37fb8933 0x3771ba33 0x3771b699 0x3771a26f 0x3769d4a5 0x3769d36d 0x33e5c439 0x31449cd5 0xb7cf 0xb774)
terminate called throwing an exception(lldb)
I think the error is the way i try to tell the app witch button it needs to set a title to, but I can not really figure out how to get it to take on the value of my array and use it as the button name.
I'm pretty new in iPhone iOS development, so bear with me if the answer is simple ;)
You are not referencing the button instances but some strings within that array. Now within your loop, you are trying to invoke the method setTitle:forState: on those strings which does not exist for NSString instances.
Try the following:
NSArray *myArray = [NSArray arrayWithObjects:_button1, _button2, _button3, _button4, _button5, _button6, _button7, _button8, _button9, _button10, nil];
This will place the actual button instances into your array, as intended and your code should work fine.
you should do something like [myButton setTitle:[myArray objectAtIndex:i] forState: UIControlStateNormal]
at the moment you are passing the setTitle message to a string type which - of course - should result in a crash...
hope it helps

Resources