Как просмотреть пользовательский UITableViewCell в iOSIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Как просмотреть пользовательский UITableViewCell в iOS

Сообщение Anonymous »

Я пытаюсь отобразить результаты в UITableView в своем приложении iOS, используя специальный UITableViewCell. Я могу просмотреть содержимое моего массива, если использую свойства textLabel и DetailTextLabel ячейки, но если я попытаюсь связать UITableView с пользовательским классом ячеек для отображения содержимого массива, я получу только значения по умолчанию из интерфейса. В моей таблице отображается Builder.
Это соответствующий код, который у меня есть:

Код: Выделить всё

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}

// Configure the cell...

TransactionList *tList = [_list objectAtIndex:indexPath.row];
/*
cell.transaction.text = tList.transaction;
cell.type.text = tList.type;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"ddMMYYYY"];

NSString *dateAsString = [formatter stringFromDate:tList.date];
cell.date.text = dateAsString;

*/

//this code below displays the contents just fine, but the block of code above does not.

cell.textLabel.text = tList.transaction;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", tList.type, tList.status];

return cell;
}
Приведенный ниже метод используется в моем классе CustomTableCell:

Код: Выделить всё

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code

self.selectionStyle = UITableViewCellSelectionStyleNone;

self.contentView.frame = CGRectMake(0, 0, 320, 80);

_transaction = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 80, 40)];
[_transaction setBackgroundColor:[UIColor clearColor]];
[_transaction setFont:[UIFont systemFontOfSize:12]];
[_transaction setNumberOfLines:2];
[_transaction setLineBreakMode:NO];
[self.contentView addSubview:_transaction];

_date = [[UILabel alloc] initWithFrame:CGRectMake(100, 5, 80, 40)];
[_date setBackgroundColor:[UIColor clearColor]];
[_date setFont:[UIFont systemFontOfSize:12]];
[_date setNumberOfLines:2];
[_date setLineBreakMode:NO];
[self.contentView addSubview:_date];

_type = [[UILabel alloc] initWithFrame:CGRectMake(200, 5, 80, 40)];
[_type setBackgroundColor:[UIColor clearColor]];
[_type setFont:[UIFont systemFontOfSize:12]];
[_type setNumberOfLines:2];
[_type setLineBreakMode:NO];
_type.lineBreakMode = NO;
[self.contentView addSubview:_type];

}
return self;
}
Где _transaction, _date и _type — метки. Вот скриншот моего конструктора интерфейсов внутри MainStoryboard:
Изображение

Я пробовал изменить стиль с «Базового» на «Пользовательский» на «Субтитры», но это не помогло. Он отображает только значения таблицы по умолчанию, и эти настройки меняют способ их отображения, но содержимое моего массива ни при каких обстоятельствах не отображается в таблице. Что я делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/177 ... ell-in-ios
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «IOS»