Пользовательские Uicells в UIviewController дают ошибку - PullRequest
1 голос
/ 10 октября 2011

Я пытаюсь отобразить пользовательский TableView на UIViewController, но получаю ошибку "UITableView dataSource должен вернуть ячейку из tableView: cellForRowAtIndexPath:"

Я подключил TableView к источнику данных и делегату.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Custom";

    Custom *cell = (Custom *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {

        NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"Custom" owner:self options:nil];

         for (id currentObject in topLevelObjects)
        {

            if ([currentObject isKindOfClass:[Custom class]])
            {
                cell = (Custom *) currentObject;
                 break;
            } 
        }  
     }

     cell.textLabel.text =[arr objectAtIndex:indexPath.row];

пожалуйста, помогите

Ответы [ 3 ]

2 голосов
/ 10 октября 2011

enter image description here enter image description here


#import <UIKit/UIKit.h>

@interface VocaTableCell : UITableViewCell 
{
    UILabel *vocaLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *vocaLabel;

@end

#import "VocaTableCell.h"


@implementation VocaTableCell
@synthesize vocaLabel;

- (void)dealloc {
    [vocaLabel release];
    [super dealloc];
}
@end

Ваш код неправильный. ниже код см. плз. Я исправил.

Ниже приведен код ссылки Befoe, вы правильно делаете customTableCell? ниже список проверьте плз.

Существует несколько способов создания custtomTablecell.

Моя манера очень популярна.

  1. CustomTabelCell Владельца файла должен быть NSObject . (Очень важное значение по умолчанию: Maybe UITableCell. Необходимо изменить владельца файла. NSObject (NSObject означает тип id!))

  2. CustomTableCell связывает класс объекта с вашим классом CustomTableCell.

  3. Ссылка на ссылку Outlets не является владельцем файла, должна быть Вашей прямой ссылкой на CustomTableCell.


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Custom";

    Custom *cell = (Custom *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell)
    {
        UINib *nib = [UINib nibWithNibName:@"Custom" bundle:nil];
        NSArray *arr = [nib instantiateWithOwner:nil options:nil];
        cell = [arr objectAtIndex:0];
    }

    cell.textLabel.text =[arr objectAtIndex:indexPath.row];
}
0 голосов
/ 10 октября 2011

Вы добавили оператор возврата?И является ли Custom подклассом UITableViewCell?

0 голосов
/ 10 октября 2011

Похоже, вы не возвращаете созданную ячейку в конце метода. Добавить 'возврат ячейки;' в конце и ошибка исчезнет.

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