У меня есть родительский объект UITableViewController с именем ObjectA и производным ObjectB.Ребенка dataSource методы не называются
МОЯ ЦЕЛЬ: Override cellForRowAtIndexPath: метод просто изменить клетки внешний вид
Objecta методы называются правильно так:
- numberOfRowsInSection: вызывается в родителя, OK
- numberOfSectionsInTableView: вызванный в родитель, OK
- cellForRowAtIndexPath: вызывается в родителя, НЕПРАВИЛЬНО
это то, что я сделал:
/**
* ObjectA
*/
@interface ObjectA : UITableViewController
@end
@implementation ObjectA
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return list.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Layout by ObjectA rules */
}
@end
/**
* ObjectB
*/
@interface ObjectB : ObjectA
@end
@implementation ObjectB
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Layout by ObjectB rules */
NOT CALLED
}
@end
EDIT:
объекта выделяются программно, так что не проблема, связанная с IB деклараций.
EDIT2:
МОЙ КОД глючит ... Я НАПИСАЛ тестовый проект и все работает ... извините
/**
* ObjectA
*/
@interface ObjectA : UITableViewController {
NSArray *list;
}
-(void)setList: (NSArray *)l;
@end
@implementation ObjectA
-(void)setList: (NSArray *)l {
list = l;
[self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return list.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
cell.textLabel.text = [list objectAtIndex:indexPath.row];
return cell;
}
@end
/**
* ObjectB
*/
@interface ObjectB : ObjectA
@end
@implementation ObjectB
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
cell.textLabel.text = @"child";
return cell;
}
@end
/**
* View controller
*/
@interface ViewController() {
NSArray *list;
ObjectA *obj;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
list = @[@"test1", @"test2", @"test3", @"test4", @"test5"];
obj = [[ObjectB alloc] initWithStyle:UITableViewStylePlain];
obj.view.frame = self.view.frame;
[self.view addSubview:obj.view];
[obj setList:list];
}
Что вы подразумеваете под неправильным? –
ожидаемый результат: cellForRowAtIndexPath: вызван в РЕБЕНОК, ОК –