I have two separate xib. One hold main screen as child of UIView and also UICollectionView. Second xib contains UICollectionCell. If I just run my code as it is, it is working. (First xib with UIView is used in storyboard, its places in UIViewController).
I have this in - (void) awakeFromNib
UINib *cellNib = [UINib nibWithNibName:#"ViewCellNIB" bundle:nil];
[self.todayScroll registerNib:cellNib forCellWithReuseIdentifier:#"TodayCellID"];
Now, I want to add some IBOutlet connections into ViewCellNIB. If I do this, my code crash in runtime with this error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0xb068b10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key temporaryLabel.'
I have this:
#property (weak, nonatomic) IBOutlet UILabel *temporaryLabel;
connected to UILabel on UICollectionViewCell
How can I repair this ?
Ok.. I have found solution. My mistake. I have incorrectly connect IBOutlet in Designer. I have to connect outlets via main UICollectionViewCell and not directly by dragging connection from element to code.
Related
I upgrade my iphone's ios ver to 10.0 and xcode's ver to 8.0(beta).
Source code well done in xcode ver 7.3.1.
but, when i run code in xcode 8.0,
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key idTextField.'
show up.
there is no '!' mark in xib. how can i fix it?
xib image
#interface TutorialViewController () <UIScrollViewDelegate>
{
IBOutlet UIScrollView *tutorialScrollView;
IBOutlet UIPageControl *pageControl;
IBOutlet UIButton *showTermsButton;
IBOutlet UIButton *showPrivacyPolicyButton;
ContactsManager *contactsManager;
IBOutlet UITextField *idTextField;
IBOutlet UITextField *pwTextField;
}
-(IBAction)showTerms:(id)sender;
-(IBAction)showPrivacyPolicy:(id)sender;
-(IBAction)start:(id)sender;
-(IBAction)startWithFacebook:(id)sender;
-(IBAction)goToSignUpPage:(id)sender;
#end
#implementation TutorialViewController
I have a UICollectionViewController which delegates UICollectionViewDataSource and UICollectionViewDelegate. My collection view displays 2 sections with multiple rows of data and works fine.
I have created a Section Header (in IB Attributes Inspector -> Accessories) which then subclasses UICollectionReusableView with the SWOHighScoreHeader class:
#interface SWOHighScoreHeader : UICollectionReusableView
#property (strong, nonatomic) IBOutlet UILabel *hiScoreHead;
#end
I set this class (SWOHighScoreHeader) as the Custom Class for the UICollectionReusableView in IB.
In the UICollectionViewController I use the method:
-(UICollectionReusableView*)collectionView:(UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
SWOHighScoreHeader *highScoreHeaderView = nil;
if ([kind isEqual:UICollectionElementKindSectionHeader]) {
highScoreHeaderView = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:#"highScoreTableHead"
forIndexPath:indexPath];
}
return highScoreHeaderView;
}
The identifier highScoreTableHead is set as the UICollectionReusableView Collection Reusable View Identifier in IB.
At this stage, the section headers display correctly, albeit with the default label text.
My issue comes when I connect the IBOutlet UILabel hiScoreHead property with the outlet in IB. When I do this, the program crashes with:
Unknown class SWOHighScoreHeader in Interface Builder file.
** * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key submitButton.'
I've tried deleting the outlet connection and reconnecting but still nothing. Any ideas where I am going wrong?
Add the following property to SWOHighScoreHeader:
#property (weak) IBOutlet UIButton* submitButton;
Or try to find out which object in your storyboard is expecting the submitButton to actually exist.
An IBoutlet must always be a weak property, otherwise its container will not be deallocated.
I solved this by using Tags instead of IBOutlets ie
UILabel *hiScoreHeader = (UILabel *)[highScoreHeaderView viewWithTag:101];
hiScoreHeader.text = #"Header Text";
I'm not sure why the IBOutlets don't work but at least I have a solution.
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.
I've been trying to make a custom UITableViewCell with a UIScrollView.
I have a .xib which contains a UITableViewCell (that contains only a UIScrollView) and a UIView that is the content view for the cell's scrollView.
Alright, now here's the code for the UITableView that should display the custom cell :
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.tableView registerNib:[UINib nibWithNibName:#"RecessCell" bundle:nil] forCellReuseIdentifier:#"Recess"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
RecessCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Recess"];
return cell;
}
The header for the RecessCell class:
#import <UIKit/UIKit.h>
#interface RecessCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) IBOutlet UIView *contentView;
#end
scrollView is an outlet for the UIScrollView inside each cell.
contentView is an outlet for the UIScrollView's content view.
Well, so far everything seems legit, but when I run the app:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class
is not key value coding-compliant for the key contentView.'
I've read plenty about that run-time error, all I could find is :
I need to verify that the contentView is actually declared in
the header. (as you can see, it is declared there)
I need to change UITableViewCell to RecessCell in cellForRow, which I did.
How can I fix this problem? is creating custom UITableViewCells so difficult?
You shouldn't create another outlet called contentView in your header file. The UITableViewCell already has a property called contentView.
Also if you are creating a .xib with a UITableVieCell and you are adding views to the UITableViewCell the views will be added to the content view.
So what you need is to go in your .xib file and remove the link between the view that is linked to your contentView IBOutlet. (You can also delete that view, but be careful so that you won't delete the subviews)
I have a custom View
#interface Slip : UIView{
UIButton *number1;
}
#property (nonatomic, assign) IBOutlet UIButton *number1;
#end
with a nib file, the "Slip" is the fileĀ“s owner of the nib File.
I initialize the View in a ViewController like this:
self.slip1 = [[[NSBundle mainBundle]loadNibNamed:#"SlipNib" owner:self options:nil] objectAtIndex:0];
[self.slip1 setFrame:CGRectMake(0.0f, 0.0f, 307.0f, 322.0f)];
[self.slips addSubview:self.slip1];
now I want to access the member of the Slip
[self.slip1.number1 setSelected:YES];
this line throws an exception
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x755e9d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key number1.'
How can I access the member (number1). I have 12 of these views in my ViewController and need to access them seperately. Any help much appreciated.
It sounds like you haven't connected the IBOutlet to the button in Interface Builder. You should right click and drag from 'Files Owner' to the button and then select button1.
It's a problem associated with the IBOutlet not being linked properly to the button as nibs use KVC under the hood. You may also need to connect the root view of the nib to an IBOutlet in your UIView subclass.
Check out my other post here if you need more info on how to load UIView subclasses from nibs
UIView is not showing up in UIScrollView