2016-04-28 3 views
0

У меня есть UIPickerViewОбновление UITableView клетки в зависимости от UIPickerView

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView  
{  
return 1; 
} 

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
return seasons.count; 
} 

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
if ([season selectedRowInComponent:0] == 6) { 
    matches = [[NSMutableArray alloc] initWithCapacity: 20]; 
    [matches insertObject:[NSMutableArray arrayWithObjects:@"aaa", @"bbb", @"1-0", @"15-03-2010", nil] atIndex:0]; 
} else if 
. 
. 
. 
} 

Тогда у меня есть UITableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return matches.count; 
} 

- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
static NSString *simpleTableIdentifier = @"customCell"; 

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 
cell.team1.text = matches[indexPath.row][0]; 
cell.team2.text = matches[indexPath.row][1]; 
cell.score.text = matches[indexPath.row][2]; 

return cell; 
} 

Так прямо сейчас UITableView заполняется объектами из matches массива, который я инициализировать в мой viewDidLoad. Как я могу обновить содержимое ячеек в зависимости от выбранной строки UIPickerView?

ответ

2

Просто позвоните [self.tableView reloadData]; после того, как вы обновите массив matches.

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
if ([season selectedRowInComponent:0] == 6) { 
    matches = [[NSMutableArray alloc] initWithCapacity: 20]; 
    [matches insertObject:[NSMutableArray arrayWithObjects:@"aaa", @"bbb", @"1-0", @"15-03-2010", nil] atIndex:0]; 
} else if 
. 
. 
. 

[self.tableView reloadData]; 
} 

Это предполагает, что self является и представление таблицы данных источника/делегата и источник данных выбора режима просмотра/делегат

+0

это работает, но я получил 'нет индекса пути для ячейки таблицы не будучи reused' – fabersky

+0

Где эта ошибка происходит? Вы вызываете 'dequeueReusableCellWithIdentifier' где-нибудь там, где находится' cellForRowAtIndexPath'? – rmaddy

+0

@fabersky, попробуйте использовать 'dequeueReusableCellWithIdentifier: forIndexPath:' вместо просто 'dequeueReusableCellWithIdentifier:'. –