ここに追加したスクリーンショットには、セクションに動的データがあります。各セクションには 1 つの行があり、その中にラベルと値があります。私の問題は、値の数を追加または変更すると、セクション 'y' マージンが変更されることです。誰か知っていたら助けてください
ここに私のコードがあります
- (UIView *)tableView:(UITableView *)tableView1 viewForHeaderInSection:(NSInteger)section{
UIView *section1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView1.bounds.size.width, tableView1.bounds.size.height)] ;
[section1 setBackgroundColor:[UIColor clearColor]];
return section1;
}
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section !=0){
return 22;
}
return 0.0;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0;
}
//dynamic decide no of sections in table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(tagLastbutton == lastRow){
lastRow = lastRow +1;
return lastRow;
}
return lastRow;
//[self.arrayObjects count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
// Return YES to allow the user to reorder table view rows
//
- (BOOL)tableView:(UITableView *)tableView
canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
// Return a cell containing the text to display at the provided row index.
//changing background according to input
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyuSocialNetworkCell";
CreateNewProfileViewCell * cell = (CreateNewProfileViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nibObjects= [[NSBundle mainBundle] loadNibNamed:@"CreateNewProfileViewCell" owner:nil options:nil];
for(id currentObject in nibObjects)
{
if([currentObject isKindOfClass:[CreateNewProfileViewCell class]])
{
cell = (CreateNewProfileViewCell *) currentObject;
break;
}
}
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
//[indexPath.row color]
// if([self.subCategoryString length] != 0){
// cell.addFoodAllergyLabel.text = self.subCategoryString;
// }
NSString *str;
if(indexPath.section < [self.namesFoodSubCategoryLabels count]){
str = [self.namesFoodSubCategoryLabels objectAtIndex:indexPath.section];
}
int len=str.length;
NSLog(@"Ch ###########################%u",len);
len=floor(len/29);
NSLog(@"Ch ##After Row##################%u",len);
len++;
// len++;
/*
CGRect frameCell = CGRectMake(cell.frame.origin.x, cell.frame.origin.y+newCellPosition, cell.frame.size.width, cell.frame.size.height);
cell.frame = frameCell;
*/
CGRect frame = CGRectMake(cell.addFoodAllergyLabel.frame.origin.x, cell.addFoodAllergyLabel.frame.origin.y, cell.addFoodAllergyLabel.frame.size.width, cell.addFoodAllergyLabel.frame.size.height*len);
cell.addFoodAllergyLabel.numberOfLines = len;
cell.addFoodAllergyLabel.frame = frame;
CGRect frameMidBox = CGRectMake(cell.midMainRowBoxImageView.frame.origin.x, cell.midMainRowBoxImageView.frame.origin.y, cell.midMainRowBoxImageView.frame.size.width, cell.midMainRowBoxImageView.frame.size.height*len);
cell.midMainRowBoxImageView.frame = frameMidBox;
CGRect frameLowerCornerBox = CGRectMake(cell.lowerRowCornerImageView.frame.origin.x, cell.lowerRowCornerImageView.frame.origin.y+((len*26)-26), cell.lowerRowCornerImageView.frame.size.width, cell.lowerRowCornerImageView.frame.size.height);
newCellPosition = cell.lowerRowCornerImageView.frame.origin.y+22;
cell.lowerRowCornerImageView.frame = frameLowerCornerBox;
CGRect frameButtonImage = CGRectMake(cell.addFoodAllergyButton.frame.origin.x, cell.addFoodAllergyButton.frame.origin.y+((len * 13)-13), cell.addFoodAllergyButton.frame.size.width, cell.addFoodAllergyButton.frame.size.height);
cell.addFoodAllergyButton.frame = frameButtonImage;
cell.addFoodCategoryImageView.frame = frameButtonImage;
NSLog(@"Array&&&&&&&&&&&&&&&&%@",self.namesFoodSubCategoryLabels);
NSLog(@"indexPath.row %u",indexPath.row);
if(indexPath.section < [self.namesFoodSubCategoryLabels count]){
cell.addFoodAllergyLabel.text = [self.namesFoodSubCategoryLabels objectAtIndex:indexPath.section];
cell.addFoodCategoryImageView.image = [UIImage imageNamed:[self.imagesFoodCategories objectAtIndex:indexPath.section]];
}
//CGRect frame = CGRectMake(0, 0, 60, 60);
//cell.frame=frame;
cell.addFoodAllergyButton.tag = indexPath.section+1;
cell.addFoodAllergyLabel.tag = indexPath.section+1;
[cell.addFoodAllergyButton addTarget:self action:@selector(addFoodAllergyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(CGFloat) tableView:(UITableView *) tableView1 heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
for(int i=0 ; i< [self.namesFoodSubCategoryLabels count] ; i++){
NSString *str = [self.namesFoodSubCategoryLabels objectAtIndex:i];
int len=str.length;
NSLog(@"Ch ######heightForRow#####################%u",len);
len=floor(len/29);
len++;
//len++;
NSLog(@"Ch ##After heightForRow###################%u",len);
return ((len*26)+11);
}
return 37;
}
背景、ラベル、セクションの高さを動的に変更していますが、セクション y を動的に処理できません。スクリーンショットが示すように、私の問題は、2 つのセクションごとに変更される y 位置のセクション マージンを管理することです。