-1
У меня есть табличное представление с json, и я хотел бы, например, если моя метка = Франция в ячейку другого цвета, возможно ли это? как?Изменить цвет одной ячейки (Objective-C)
У меня есть табличное представление с json, и я хотел бы, например, если моя метка = Франция в ячейку другого цвета, возможно ли это? как?Изменить цвет одной ячейки (Objective-C)
Да, вот минималистский пример, используя UITableViewController. В идеале не должно быть слишком много логики в вашем
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
метод, но это всего лишь простой пример.
#import "TableViewController.h"
@interface TableViewController()
@property (readonly, nonatomic, strong) NSArray *countriesArray;
@end
@implementation TableViewController
- (id)init {
self = [super init];
if (!self) {
return nil;
}
_countriesArray = @[@"France", @"Germany", @"Spain", @"Norway", @"Denmark", @"United States"];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.countriesArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if ([self.countriesArray[indexPath.row] isEqualToString:@"France"]) {
cell.backgroundColor = [UIColor grayColor];
}
else {
cell.backgroundColor = [UIColor whiteColor];
}
cell.textLabel.text = self.countriesArray[indexPath.row];
return cell;
}
@end
Да, это возможно. – trojanfoe
@trojanfoe как? –
Как вы создаете свои ячейки? – Niko