클래스가 키 값 코딩을 준수하지 않습니다.
이 질문에 이미 답변이 있습니다.
이 오류의 의미를 알고 있지만 실제로 어려움을 겪고 있으며 누군가의 도움이 필요합니다.
2010-09-21 15:03:11.562 Stocks[5605:207] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[<NSObject 0x499fb20>
setValue:forUndefinedKey:]: this class is not key value coding-compliant
for the key actionText.'
여기에 내 코드가 있습니다.
AlertCell.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AlertCell : UITableViewCell {
IBOutlet UILabel *actionText;
}
@property (retain, nonatomic) UILabel *actionText;
@end
과
AlertCell.m
@implementation AlertCell
@synthesize actionText;
- (void)dealloc {
[actionText release];
[super dealloc];
}
@end
문제는 바로 거기에서 발생합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
AlertCell *cell =
(AlertCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AlertCell"
owner:nil
options:nil];
for (id oneObject in nib) {
if ([oneObject isKindOfClass:[UITableViewCell class]]) {
cell = (AlertCell *)oneObject;
break;
}
}
}
cell.actionText.text = [arrayAlert objectAtIndex:indexPath.row];
return cell;
}
이 줄에서 :
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AlertCell"
owner:nil
options:nil];
요청한대로 TableViewCOntroller에 대한 내 헤더는 다음과 같습니다.
#import <UIKit/UIKit.h>
@interface AlertesViewController : UITableViewController {
NSMutableArray *arrayAlert;
}
그리고 내 XIB 파일 (XML)을 볼 수 있습니다 : http://pastebin.com/FDVzLYZu
@종료
누구든지 나를 도울 수 있습니까? 고마워요!
이 문제를 해결할 수있는 몇 가지 옵션이 있습니다. 가장 적절한 방법을 결정하도록하겠습니다.
The reason it's failing is because the owner is being passed as nil. You're binding the actionText outlet to the file's owner in IB, but then when loading the nib, the owner is nil. I'd guess that when loading with a nil owner behind the scenes an NSObject is used, which is why you're getting the key/value error.
My previous advice to pass the cell as the owner would also fail as I didn't know how the Nib is constructed; the cell is nil as you've yet to create it (and dequeue is passing nil back, so even pass cell as the owner is still essentially passing nil).
Two options:
- Instantiate a new cell in your -cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation, and pass that new cell as the owner (but i'd guess that this isn't the best solution for you)
- Or, and I'd suggest this is the better solution, change the binding of actionText in your nib file to the Alert Cell and not the file's owner (You have File's Owner and an Alert Cell - bind the UILabel to the actionText outlet of the Alert Cell, and not the File's owner, which is what's being done at present) - I suspect this is what you want. With that in mind file's owner can become an NSObject again.
------- Original answer kept below as the file's owner class is also a common cause for this error -------
It suggests that you've 'instantiated' an AlertCell in InterfaceBuilder, and you're binding something to actiontext, but the class isn't set to AlertCell, it's still NSObject?
Take a look at the class text box on the identify tab of the tool palette for that object in Interface Builder. The class should be AlertCell, but i'd guess it's still set to NSObject.
As an aside, and feel free to ignore this advice, but there are a couple of extra things i'd encourage you to do, purely from an Objective C expectations/conventions point of view:
- Name your files after your class (upper case the first character of the filename).
- Prefix your class names; two uppercase characters, typically your initials (i'd name it DWAlertCell, for example).
you probably based your code on a web tutorial such as the one at http://www.e-string.com/content/custom-uitableviewcells-interface-builder or http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
Your problem (and I'm 99% sure this is where you tripped up, I just made the same mistake) is that in interface builder you linked your IBOutlets from File's Owner when you should link them from the cell view. This is why you are getting the errors.
I had the same problem, and I could not find the mentioned variable/element in any file. I followed the following steps.
Environment: Xcode 6
- Go to the Xib file, and right click (Ctrl+Mouse Click) on each UI element to see its associations.
- In its referencing outlets section, you will be able to locate the erroneous association.
- Remove that association
- Clean the solution and build folder
- Reset Simulator
- Rebuild and run the project.
check UIControl Referencing OutLet Property Name from nib/StoryBoard File
Make sure select cell to put custom class not File's Owner to add custom class on right side top and if You have done so, Before you make any changes remove outlet connection and then remove custom class from File's Owner and add Class to Cell view
Maybe it helps: Indentity Inspector when you have selected file's owner - UITableViewCell, when you have selected the cell inside Objects Your custom cell nane
After 2 hours on this, I realized that i forgot to
@synthesize tableView = _tableView;
Hope it helps.
Mário
#import <UIKit/UIKit.h>
@interface ReceptionDetailCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *productName;
@property (weak, nonatomic) IBOutlet UILabel *billType;
@property (weak, nonatomic) IBOutlet UILabel *bookTime;
@property (weak, nonatomic) IBOutlet UILabel *doctorName;
@property (weak, nonatomic) IBOutlet UILabel *downBillManName;
@end
Checkout out the Cell code and storyboard setting, whether they are all exist, maybe you have changed their names.
참고URL : https://stackoverflow.com/questions/3760803/class-is-not-key-value-coding-compliant
'Nice programing' 카테고리의 다른 글
Lisp의 유연성에 대한 실제적인 예? (0) | 2020.11.09 |
---|---|
PHP에서 파일 시스템 경로 문자열을 결합하는 방법은 무엇입니까? (0) | 2020.11.09 |
특정 좌표 근처의 특정 장소를 검색하는 Google지도 URL을 형성합니다. (0) | 2020.11.09 |
두 개의 날짜 시간을 비교할 때 밀리 초 무시 (0) | 2020.11.09 |
UICollectionView에서 레이아웃을 동적으로 설정하면 설명 할 수없는 contentOffset 변경이 발생합니다. (0) | 2020.11.08 |