Rob*_*Rob 67 iphone key uitableview
我知道这个错误的意思,但我真的很挣扎,我需要别人的帮助:
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.'
Run Code Online (Sandbox Code Playgroud)
这里有我的代码:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AlertCell : UITableViewCell {
IBOutlet UILabel *actionText;
}
@property (retain, nonatomic) UILabel *actionText;
@end
Run Code Online (Sandbox Code Playgroud)
和
@implementation AlertCell
@synthesize actionText;
- (void)dealloc {
[actionText release];
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
问题发生在那里:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
在这一行:
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AlertCell"
owner:nil
options:nil];
Run Code Online (Sandbox Code Playgroud)
如上所述,这是我的TableViewCOntroller的标题:
#import <UIKit/UIKit.h>
@interface AlertesViewController : UITableViewController {
NSMutableArray *arrayAlert;
}
Run Code Online (Sandbox Code Playgroud)
您可以看到我的XIB文件(作为XML):http://pastebin.com/FDVzLYZu
@结束
谁能帮我 ?非常感谢 !
the*_*rof 102
您可能将代码基于Web教程,例如http://www.e-string.com/content/custom-uitableviewcells-interface-builder或http://www.icodeblog.com/2009/05/上的教程. 24 /定制的UITableViewCell-使用接口助洗剂/
您的问题(我99%确定这是您绊倒的地方,我只是犯了同样的错误)是在界面构建器中,当您应该从单元格视图链接它们时,您从文件所有者链接了您的IBOutlet.这就是你得到错误的原因.
dan*_*aby 84
有几个选项可以解决这个问题 - 我会让你决定哪个是最合适的.
它失败的原因是因为所有者被传递为零.您将actionText插座绑定到IB中文件的所有者,但是在加载笔尖时,所有者为零.我猜想在幕后加载一个nil所有者时会使用NSObject,这就是你得到键/值错误的原因.
我以前建议将单元格作为所有者传递也会失败,因为我不知道Nib是如何构造的; 因为你还没有创建它,所以单元格是零(并且dequeue正在向后传递nil,所以即使传递单元格,因为所有者仍然基本上传递nil).
两种选择:
-------原始答案保存在下面,因为文件的所有者类也是此错误的常见原因-------
它表明你已经在InterfaceBuilder中实例化了一个AlertCell,并且你将某些东西绑定到了actiontext,但是这个类没有设置为AlertCell,它仍然是NSObject?
在Interface Builder中查看该对象的工具选项板的标识选项卡上的类文本框.该类应该是AlertCell,但我猜它仍然设置为NSObject.
顺便说一句,并且可以随意忽略这个建议,但是我鼓励你做一些额外的事情,纯粹来自Objective C期望/约定的观点:
小智 7
我有同样的问题,我找不到任何文件中提到的变量/元素.我按照以下步骤操作.
环境:Xcode 6
| 归档时间: |
|
| 查看次数: |
58873 次 |
| 最近记录: |