2016-01-15 1 views
0

Я новичок в программировании на iOS, и у меня есть проблема с подключением на одном экране двух отдельных экранных моделей. У меня есть табличный вид и обычный контроллер вида. Когда мне нужны элементы управления этого экрана, мне нужен два отдельных класса, где один наследуется от UITableView и второй из UIViewController, потому что в Objective-C я не могу создать класс, который наследуется от двух других классов. Как я могу управлять классом вида таблицы из класса контроллера вида. Должен сказать, что простая композиция не решает мою проблему, потому что я не знаю, как подключить динамический класс к модели экрана.Создайте экран раскадровки с двумя классами наследования

Спасибо за любую помощь.

ответ

0

Вы должны использовать UITableViewDelegate и UITableViewDataSource

@interface ViewController()<UITableViewDelegate,UITableViewDataSource> 

@end 

и установить для UITableView .delegate и .datasource или связать его в раскадровку

0

Спасибо за помощь, но этот ответ должен быть завершен, потому что в код вида контроллера должен быть добавлены несколько функций:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
 
    return [regions count]; 
 
} 
 

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
 
    // Number of rows is the number of time zones in the region for the specified section. 
 
    Region *region = [regions objectAtIndex:section]; 
 
    return [region.timeZoneWrappers count]; 
 
} 
 

 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
 
    // The header for the section is the region name -- get this from the region at the section index. 
 
    Region *region = [regions objectAtIndex:section]; 
 
    return [region name]; 
 
} 
 

 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
 
    static NSString *MyIdentifier = @"MyReuseIdentifier"; 
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
 
    if (cell == nil) { 
 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]]; 
 
    } 
 
    Region *region = [regions objectAtIndex:indexPath.section]; 
 
    TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row]; 
 
    cell.textLabel.text = timeZoneWrapper.localeName; 
 
    return cell; 
 
}