【发布时间】:2011-11-30 05:00:19
【问题描述】:
好的,我知道网上有大量关于此的文档,我觉得我已经尝试了所有方法,但仍然无法正常工作。我正在尝试使用我在 IB 中创建的自定义单元格来实现表格视图。 CustomCell.xib 文件的所有者是UITableViewCell。这是我在其中实现表格视图的头文件:
#import <UIKit/UIKit.h>
@interface QuickCalcController : UIViewController<UITabBarDelegate, UITableViewDelegate, UITableViewDataSource>{
NSMutableArray *numbers;
NSMutableArray *discount_numbers;
}
@property (nonatomic, retain) IBOutlet UITableView *tblView;
@end
这是实现文件中的代码:
- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"DiscountCellController";
DiscountCellController *cell = [tblView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSLog(@"New Cell Made");
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DiscountCellController" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[DiscountCellController class]])
{
cell = (DiscountCellController *)currentObject;
break;
}
}
}
cell.standardLabel.text = @"hi";//[discount_numbers objectAtIndex:indexPath.row];
cell.discountLabel.text = @"hi";//[discount_numbers objectAtIndex:indexPath.row];
NSLog(@"setting the cell");
return cell;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tblView
{
return 1;
}
- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection: (NSInteger)section
{
return nil;
}
- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tblView {
return nil;
}
我已将自定义单元格中的标签连接到DiscountCellController 中的standardLabel 和discountLabel。我收到此错误:
[3390:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x4e227d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key standardLabel.'
因为我错过了什么?
【问题讨论】:
-
我认为你需要转换 DiscountCellController *cell = (DiscountCellController *)[tblView... 一件事。另外,你能分享一下 DiscountCellController 的代码吗?
标签: iphone xcode4 uitableview