2016-02-01 2 views

ответ

0

Да, вот минималистский пример, используя 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 
Смежные вопросы