iphone uitableview с пользовательской ячейкой - xcode 4 - PullRequest
1 голос
/ 04 октября 2011

Хорошо, я знаю, что в Интернете есть тонны документации по этому поводу, и я чувствую, что перепробовал все и до сих пор не могу заставить его работать.Я пытаюсь реализовать просмотр таблицы с помощью пользовательской ячейки, созданной в 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; 
}

Я подключил метки в пользовательской ячейкедо standardLabel и discountLabel в DiscountCellController.Я получаю эту ошибку:

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

Как я что-то упустил?

1 Ответ

3 голосов
/ 04 октября 2011

Да, вы есть. Прежде всего, это распространенная ошибка. В файле nib для ячейки определите владельца файла как NSObject. В вашем nib-файле у вас должен быть UITableViewCell, вот и все. Нет просмотра. Измените тип UITableViewCell на DiscountCellController. Теперь важная часть - щелкните правой кнопкой мыши DiscountCellController, чтобы сделать ссылки на ваши ярлыки и т. Д. НЕ СДЕЛАЙТЕ ССЫЛКИ ИЗ ВЛАДЕЛЯ ФАЙЛА

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...