Я разрабатываю приложение, в котором в основном используется 1 контроллер вида. Когда пользователь нажимает кнопку, он заполняет массив и использует этот массив для заполнения скрытого вида таблицы с помощью [myTable reloadData].iOS UITableVIew увеличивает размер ячейки при множественной перезагрузке
Затем он может нажимать кнопку, и таблица исчезает, а с другой кнопкой она должна повторять то же самое, заполнять тот же массив той же функцией и перезагружать данные.
Но когда я это делаю, размеры ячейки увеличиваются, и это увеличивает мой размер подкатегории таблицы и, таким образом, использует прокрутку для отображения всех данных, в то время как первый раз все это помещается внутри подматрицы таблицы.
Я, вероятно, сделал ошибку в настройках Раскадровки моего приложения, но вот мои методы делегирования только в случае, если:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"playerCell" forIndexPath:indexPath];
cell.textLabel.text = [NSMutableString stringWithFormat:@"Player %ld", (((Player *)[topPlayersArray objectAtIndex:indexPath.row]).playerID + 1)];
//display the player's poiunts
cell.detailTextLabel.text = [NSMutableString stringWithFormat:@"Points: %ld", (((Player *)[topPlayersArray objectAtIndex:indexPath.row]).playerScore)];
return cell;
}
//custom font and color for the cell
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//set up the cell's font
cell.textLabel.font = [UIFont fontWithName:@"Aka-AcidGR-ScrachThis" size:34.0];
cell.detailTextLabel.font = [UIFont fontWithName:@"Aka-AcidGR-ScrachThis" size:24.0];
cell.detailTextLabel.textColor = [UIColor whiteColor];
//set the color of the label
if(indexPath.row == 0)
{
//set color to gold for first player
cell.textLabel.textColor = [UIColor colorWithRed:252.0/255.0 green:194.0/255.0 blue:0 alpha:1.0];
}
else if(indexPath.row == 1)
{
//set color to silver for second player
cell.textLabel.textColor = [UIColor colorWithRed:191.0/255.0 green:191.0/255.0 blue:191.0 alpha:1.0];
}
else
{
//set color to bronze for 3rd player
cell.textLabel.textColor = [UIColor colorWithRed:0.647 green:0.443 blue:0.392 alpha:1.0];
}
}
//return th e number of rows, should be 0 when the game starts and 2 or 3 depending on the number of players (2 for 2, 3 for 3 or more)
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [topPlayersArray count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//create header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//create the header subview
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 48)];
//create the section title label
UILabel *labelHeader = [[UILabel alloc] initWithFrame:CGRectMake (0,0,320,44)];
//set it to the scrachThis font and white color and center align the text
labelHeader.font = [UIFont fontWithName:@"Aka-AcidGR-ScrachThis" size:34.0];
labelHeader.textColor = [UIColor whiteColor];
labelHeader.textAlignment = NSTextAlignmentCenter;
//set the text and return the headerView
if(thisGame.gameHasEnded)
{
labelHeader.text = @"Winners:";
}
else
{
labelHeader.text = @"Leading Players:";
}
[headerView addSubview: labelHeader];
return headerView;
}
И да, таблица должна иметь максимум 3 клеток
Смущающий простой xD. благодаря –