I am facing an issue which I have tried to resolve but am yet to find a solution. I am using Xcode4.5 and iOS 6.This is my code:
viewController.h file:
#import <UIKit/UIKit.h></i>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UISegmentedControl *colorChoice;
#property (weak, nonatomic) IBOutlet UIWebView *flowerView;
#property (weak, nonatomic) IBOutlet UIWebView *flowerDetailView;
- (IBAction)toggleFlowerdetail:(id)sender;
- (IBAction)getFlower:(id)sender;
#end
viewController.m files
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)toggleFlowerdetail:(id)sender {
self.flowerDetailView.hidden = [sender isOn];
}
- (IBAction)getFlower:(id)sender {
NSURL *imageURL;
NSURL *detailURL;
NSString *imageURLString;
NSString *detailURLString;
NSString *color;
int sessionID;
color = [self.colorChoice titleForSegmentAtIndex:self.colorChoice.selectedSegmentIndex];
sessionID = random()%50000;
imageURLString = [[NSString alloc] initWithFormat:#"http://floraphotographs.com/showrandomios.php?color=%#&session=%d",color,sessionID];
detailURLString = [[NSString alloc] initWithFormat:#"http://www.floraphotographs.com/details.php?session=%d",sessionID ];
imageURL = [[NSURL alloc]initWithString:imageURLString];
detailURL = [[NSURL alloc]initWithString:detailURLString];
[self.flowerView loadRequest:[NSURLRequest requestWithURL:imageURL]];
[self.flowerDetailView loadRequest:[NSURLRequest requestWithURL:detailURL]];
self.flowerDetailView.backgroundColor = [UIColor clearColor];
}
#end
My Error:
FlowerWeb[4784:11303] *** Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key detail.'
Any Help will appreciated. Thanks
In storyboard, check your view controller, it is connected to a property called detail.
But that property is being removed in that view controller class.
Check your xib. This might be because you accidentally removed an IBOutlet object while it was still attached to your xib file.
Check out this post as well:-
Related
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
Writing my first iphone app through this tutorial--I have a custom UIView with the method showDie and I have two UIView elements on my storyboard that I've hooked up to my ViewController. However, both the UIView elements have the error message "No visible #interface for 'UIView' declares the selector 'showDie'. I think that's because the UIViews aren't subclassing XYZDieView, but when I control-clicked from my Storyboard, only UIView appeared in the dropdown--no XYZDieView. I tried just changing the text manually in the ViewController.h, but that didn't work (I didn't think it would). Am I on the right track? How do I use my subclass? (xcode 5)
XYZDieView.m
-(void)showDie:(int)num
{
if (self.dieImage == nil){
self.dieImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
[self addSubview:self.dieImage];
}
NSString *fileName = [NSString stringWithFormat:#"dice%d.png", num];
self.dieImage.image = [UIImage imageNamed:fileName];
}
XYZViewController.h
#import <UIKit/UIKit.h>
#import "XYZDieView.h"
#interface XYZViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *sumLabel;
#property (strong, nonatomic) IBOutlet UIButton *rollButton;
#property (strong, nonatomic) IBOutlet UIView *leftDieView;
#property (strong, nonatomic) IBOutlet UIView *rightDieView;
#end
XYZViewController.m
#import "XYZViewController.h"
#import "XYZDiceDataController.h"
#interface XYZViewController ()
#end
#implementation XYZViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)rollButtonClicked:(UIButton *)sender {
XYZDiceDataController *diceDataController = [[XYZDiceDataController alloc] init];
int roll = [diceDataController getDiceRoll];
int roll2 = [diceDataController getDiceRoll];
[self.leftDieView showDie:roll];
[self.rightDieView showDie:roll2];
int sum = roll + roll2;
NSString *sumText = [NSString stringWithFormat:#"Sum is %i", sum];
self.sumLabel.text = sumText;
}
#end
Yes you're right, the problem is subclassing. In order to have a view conform to a subclass in the interface builder you need to
Click on the UIView in your storyboard
Open the right inspector panel
Click on the third tab for identity inspector
Add your class
Then try to connect it to your ViewController again.
Edit: Afterwards you may need to cast XYZDieView myView = (XYZDieView*)leftDieView;
I'm a beginner in everything programming and have been trying to implement some self learned stuff from the Big Nerd Ranch Books. But I'm really stumped by this problem, and yes, I have searched this and other forums for possible solutions with no success. Here is the code:
ANKYViewController.h:
#import <UIKit/UIKit.h>
#interface ANKYViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *weightFieldDeadlift;
#property (weak, nonatomic) IBOutlet UITextField *repFieldDeadlift;
#property (strong, nonatomic) IBOutlet UILabel *workingOneRMDeadlift;
#property (weak, nonatomic) IBOutlet UITextField *weightFieldBenchPress;
#property (weak, nonatomic) IBOutlet UITextField *repFieldBenchPress;
#property (strong, nonatomic) IBOutlet UILabel *workingOneRMBenchPress;
#property (weak, nonatomic) IBOutlet UITextField *weightFieldSquat;
#property (weak, nonatomic) IBOutlet UITextField *repFieldSquat;
#property (strong, nonatomic) IBOutlet UILabel *workingOneRMSquat;
#property (weak, nonatomic) IBOutlet UITextField *weightFieldMilitaryPress;
#property (weak, nonatomic) IBOutlet UITextField *repFieldMilitaryPress;
#property (strong, nonatomic) IBOutlet UILabel *workingOneRMMilitaryPress;
- (IBAction)calculateOneRM:(id)sender;
#end
ANKYViewController.m:
#import "ANKYViewController.h"
#interface ANKYViewController ()
#end
#implementation ANKYViewController
#synthesize weightFieldDeadlift;
#synthesize repFieldBenchPress;
#synthesize workingOneRMBenchPress;
#synthesize weightFieldSquat;
#synthesize repFieldSquat;
#synthesize workingOneRMSquat;
#synthesize weightFieldMilitaryPress;
#synthesize repFieldMilitaryPress;
#synthesize workingOneRMMilitaryPress;
#synthesize repFieldDeadlift;
#synthesize workingOneRMDeadlift;
#synthesize weightFieldBenchPress;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setWeightFieldDeadlift:nil];
[self setRepFieldDeadlift:nil];
[self setWorkingOneRMDeadlift:nil];
[self setWeightFieldDeadlift:nil];
[self setRepFieldBenchPress:nil];
[self setWeightFieldBenchPress:nil];
[self setWorkingOneRMBenchPress:nil];
[self setWeightFieldSquat:nil];
[self setRepFieldSquat:nil];
[self setWorkingOneRMSquat:nil];
[self setWeightFieldMilitaryPress:nil];
[self setRepFieldMilitaryPress:nil];
[self setWorkingOneRMMilitaryPress:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)calculateOneRM:(id)sender {
float dw = [[weightFieldDeadlift text]floatValue];
float dr = [[repFieldDeadlift text]floatValue];
float d = (dw * dr * 0.0333) + dw;
NSLog(#"Deadlift: %f", d);
NSString *deadlift = [[NSString alloc]initWithFormat:#"%f", d];
[workingOneRMDeadlift setText:deadlift];
float bpw = [[weightFieldBenchPress text]floatValue];
float bpr = [[repFieldBenchPress text]floatValue];
float bp = (bpw * bpr * 0.0333) + bpw;
NSLog(#"Bench Press: %f", bp);
NSString *benchPress = [[NSString alloc]initWithFormat:#"%f", bp];
[workingOneRMBenchPress setText:benchPress];
float sw = [[weightFieldSquat text]floatValue];
float sr = [[repFieldSquat text]floatValue];
float s = (sw * sr * 0.0333) + sw;
NSLog(#"Squat: %f", s);
NSString *squat = [[NSString alloc]initWithFormat:#"%f", s];
[workingOneRMSquat setText:squat];
float mpw = [[weightFieldMilitaryPress text]floatValue];
float mpr = [[repFieldMilitaryPress text]floatValue];
float mp = (mpw * mpr * 0.0333) + mpw;
NSLog(#"Military Press: %f", mp);
NSString *militaryPress = [[NSString alloc]initWithFormat:#"%f", mp];
[workingOneRMMilitaryPress setText:militaryPress];
}
#end
File's owner class is already stated as ANKYViewController. Linking the outlets etc was by control dragging instead of manually coding (I gave up after spending too many hours).
The error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x6c22e70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key repsField.'
There's no copy and pasting of code, and it's certainly distressing that there is no mentioning of "repsField"(instead of repFieldxxx) anywhere.
I hope that this is enough information to help lead to a solution, as I've spent days looking through other people's solutions with no success.
Thanks.
Looks like the problem is that someone is accessing the UIApplication instance with a key (repsField) that is not KVC compliant.
Update I don't think you even need to subclass to add a breakpoint. Go to the breakpoint navigator and add a symbolic breakpoint for symbol -[UIApplication setValue:forUndefinedKey:] and then run the application.
I think you can debug it by subclassing UIApplication and set a breakpoint in a dummy override of the setValue:forUndefinedKey: method.
In the file where you call UIApplicationMain add this class:
#interface TestApplication : UIApplication
#end
#implementation TestApplication
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
[super setValue:value forUndefinedKey:key]; // set breakpoint here
}
#end
And then change the third argument to UIApplicationMain to #"TestApplication", for example:
UIApplicationMain(argc, argv, #"TestApplication", NSStringFromClass([AppDelegate class]));
Now run the application and it should break into to debugger and you should be able to see the call stack causing it.
When this error message appears it is very often a bad connection in a xib file or storyboard. I'll guess that this is an old example that has a MainWindow.xib file in it, with the File's Owner set as the UIApplication class. There is most likely a connection in that xib to an outlet called repsField in the File's Owner which, of course, does not match anything in the actual class.
I am making an app that will help people with certain health conditions manage their medication. I have created a modal to add medication which works and saves the new medication using core data.
I am now trying to allow people to edit their medication after it has been saved. To do this I am trying to send a managed object of the medication to a "fibromappMedsEditViewController" and assign the information in the viewDidLoad method of the class.
I keep getting this error:
'NSInvalidArgumentException', reason: '-[UINavigationController setMed:]: unrecognized selector sent to instance 0x746dda0'
Could anybody tell me what I am doing wrong?
relevant methods in fibromappMedsListViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ //selMed declared at top of file as NSManagedObject *selMed;
selMed = [self.meds objectAtIndex:indexPath.row];
NSLog(#"SELECTED MED: %#",[selMed valueForKey:#"name"] );
UIStoryboardSegue *segueString = [NSString stringWithFormat:#"%#",#"editMeds"];
NSLog(#"%#",segueString);
[self performSegueWithIdentifier:#"editMeds" sender:indexPath];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"%#",segue.destinationViewController);
NSLog(#"%#",[selMed valueForKey:#"name"] );
fibroMappMedsEditViewController *dest = segue.destinationViewController;
dest.med = selMed;
}
The fibroMappMedsEditViewController.h
#import <UIKit/UIKit.h>
#interface fibroMappMedsEditViewController : UITableViewController
- (IBAction)saveChanges:(id)sender;
- (IBAction)deleteBtnPressed:(id)sender;
- (IBAction)dosageChanged:(id)sender;
- (IBAction)maxDosageChanged:(id)sender;
- (IBAction)cancel:(id)sender;
- (IBAction)typeChanged:(id)sender;
#property (weak, nonatomic) IBOutlet UITextField *tbName;
#property (weak, nonatomic) IBOutlet UITextField *tbDose;
#property (weak, nonatomic) IBOutlet UITextField *tbMaxDose;
#property (weak, nonatomic) IBOutlet UITextField *tbType;
#property (weak, nonatomic) IBOutlet UIStepper *stepperDose;
#property (weak, nonatomic) IBOutlet UIStepper *stepperMaxDose;
#property (weak, nonatomic) IBOutlet UISegmentedControl *changeMeasure;
#property (strong, nonatomic) NSManagedObject *med;
#end
The fibroMappMedsEditViewController.m - just the parts I altered that affect the way the controller loads
#import "fibroMappMedsEditViewController.h"
#import "fibroMappAppDelegate.h"
#import <CoreData/CoreData.h>
#interface fibroMappMedsEditViewController ()
#end
#implementation fibroMappMedsEditViewController
#synthesize tbName;
#synthesize tbDose;
#synthesize tbMaxDose;
#synthesize tbType;
#synthesize med;
double dose;
double maxDose;
- (void)viewDidLoad
{
[super viewDidLoad];
tbName.text = [med valueForKey:#"name"];//name is a string in the model
tbDose.text = [med valueForKey:#"dose"];//dose is a double in the model
tbMaxDose.text = [med valueForKey:#"maxDose"];//maxDose is a double in the model
tbType.text = [med valueForKey:#"type"];//type is a string in the model
}
If you need to see anything else please just ask.
Also, I am using storyboards for this app.
It appears from that log, that your fibroMappMedsEditViewController (which should start with a capital letter BTW) is embedded in a navigation controller. You need to get to that navigation controller's root view controller.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UINavigationController *nav = segue.destinationViewController;
fibroMappMedsEditViewController *dest = (fibroMappMedsEditViewController *)nav.topViewController;
dest.med = selMed;
}
I need an example of how to instantiate a custom view from a nib file. i wrapped my head around several stackoverflow posts but i didn't get it. Maybe i only need a hint how to do it.
what I want to do is - creating a custom view with interface builder. it should be a template so that i can instantiate it multiple times to add it to multiple view controllers.
So far I have created my custom view xib file called MyIssueView.xib. Which consists in fact just of the main view and some labels.
And I created a Subclass of UIView which is called IssueView with the Outlets for my labels in the MyIssueView.xib.
How do I now hook up the outlets with the IB? And how can I instantiate the IssueView from any ViewController?
Would be glad for an example!
Cheers.
UPDATE:
I now have
IssueView.xib
IssueView.h (UIView Subclass)
IssueView.m
My IssueView.h:
#import <UIKit/UIKit.h>
#interface IssueView : UIView
#property (weak, nonatomic) IBOutlet UILabel *label1;
#property (weak, nonatomic) IBOutlet UILabel *label2;
#property (weak, nonatomic) IBOutlet UILabel *label3;
#property (weak, nonatomic) IBOutlet UILabel *label4;
#end
My IssueView.m:
#import "IssueView.h"
#implementation IssueView
#end
My ViewController.m:
#import "AllIssuesViewController1.h"
#import "IssueView.h"
#import "UIView+NibLoading.h"
#interface AllIssuesViewController1 ()
#end
#implementation AllIssuesViewController1
- (void) loadView
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
_issueView = [IssueView loadInstanceFromNib];
}
It gives me an error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x8292580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'
I have a category that extends UIView called UIView+NibLoading.
In it is this code...
#import "UIView+NibLoading.h"
#implementation UIView (NibLoading)
+ (id)loadInstanceFromNib
{
UIView *result;
NSArray* elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
for (id anObject in elements) {
if ([anObject isKindOfClass:[self class]]) {
result = anObject;
break;
}
}
return result;
}
#end
Then when I want to instantiate a UIView subclass from a nib I just import the category and I can run...
self.issueView = [IssueView loadInstanceFromNib];\
You need to connect the labels like this...
If you connecting the labels to "File's Owner" then you'll need to remove those connections.