iphone uitableview with custom cell - xcode 4



好的,所以我知道网上有很多关于这个的文档,我觉得我已经尝试了所有的东西,仍然不能让它工作。我试图实现一个表视图与自定义单元格,我在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中的standardLabeldiscountLabel。我得到这个错误:

[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.'

我错过了什么吗?

是的,你是。首先,这是一个常见的错误。在单元格的nib文件中,将file的所有者定义为NSObject。在你的nib文件中,你应该有一个UITableViewCell,仅此而已。没有观点。改变UITableViewCell的类型为DiscountCellController。现在重要的部分-右键单击DiscountCellController使链接到您的标签等不要从文件的所有者

最新更新