Так я после урока, и я пытаюсь выяснить, как показать пользовательские ячейки -пользовательских UITableViewCell не обновляется должным образом
я определил класс, который отвечает за каждого сотовом
#import <UIKit/UIKit.h>
@interface SearchResultCell : UITableViewCell
@property(copy,nonatomic)NSString *name;
@property(copy,nonatomic)NSString *colour;
@end
.m файл -
@implementation SearchResultCell{
UILabel *_nameValue;
UILabel *_colourValue;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
CGRect nameLabelRect = CGRectMake(0,5,70,15);
UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
nameLabel.textAlignment = NSTextAlignmentLeft;
nameLabel.text = @"Name:";
nameLabel.font = [UIFont boldSystemFontOfSize:12];
[self.contentView addSubview: nameLabel];
//so this is how I would add my rating view
CGRect colourLabelRect = CGRectMake(0, 26,70, 15);
UILabel *colourLabel = [[UILabel alloc] initWithFrame: colourLabelRect];
colourLabel.textAlignment = NSTextAlignmentRight;
colourLabel.text = @"Colour:";
colourLabel.font = [UIFont boldSystemFontOfSize:12];
[self.contentView addSubview: colourLabel];
CGRect nameValueRect = CGRectMake(80,5,200,15);
_nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
CGRect colourValueRect = CGRectMake(80,25,200,15);
_colourValue = [[UILabel alloc] initWithFrame:colourValueRect];
[self.contentView addSubview: _colourValue];
}
return self;
}
- (void)setName:(NSString*)n {
if(![n isEqualToString:_name]){
_name = [n copy];
_nameValue.text = _name;
}
}
- (void)setColor:(NSString *)c
{
if (![c isEqualToString:_colour]) {
_colour = [c copy];
_colourValue.text = _colour;
} }
Это мой чертежный стол
ме--(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SearchResultCell *cell = [self.resultTable dequeueReusableCellWithIdentifier:CellTableIdentifier];
NSDictionary *rowData = self.resultsTuples[indexPath.row];
cell.name = rowData[@"Name"];
cell.colour = rowData[@"Color"];
return cell;
}
Здесь я инициализирую результаты результатов и т. Д.
- (void)viewDidLoad
{
[super viewDidLoad];
self.resultsTuples = @[
@{@"Name" : @"MacBook", @"Color" : @"White"},
@{@"Name" : @"MacBook Pro", @"Color" : @"Silver"},
@{@"Name" : @"iMac", @"Color" : @"Silver"},
@{@"Name" : @"Mac Mini", @"Color" : @"Silver"},
@{@"Name" : @"Mac Pro", @"Color" : @"Silver"}];
[self.resultTable registerClass:[SearchResultCell class] forCellReuseIdentifier: CellTableIdentifier];
// Do any additional setup after loading the view.
}
То, что я вижу, это всего лишь две статические метки (имя и цвет), а не все, что заселено из массива. Я проверил, что что-то действительно установлено - и это так, поэтому я не уверен, почему это не работает.
Может ли кто-нибудь помочь?
В чем проблема, с которой вы сталкиваетесь? –