gpt4 book ai didi

iphone - 如何动态更改tableview ipad中的行高

转载 作者:行者123 更新时间:2023-12-01 18:02:36 24 4
gpt4 key购买 nike

嗨,我是 iPad 开发的新手。所以我使用 web 服务在 tableview 中显示数据。那么如何更改我尝试过的每个单元格的行高,但它显示该单元格的高度更高?
我使用三个数组在 tableview 中显示数据所以如果我通过 web 服务向数组提供更多数据。那么如何更改表格 View 的每一行。谁能帮我 ?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [arrOutline1 count] + [arrOutline2 count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((indexPath.row)%2==0) {
return 100;
}
else {
//strData3 =[[NSMutableString alloc]init];
NSLog(@" the data is %@",[arrOutline3 objectAtIndex:countRow]);

//strData3 = [NSMutableString stringWithFormat:@"%@",[arrOutline3 objectAtIndex:countRow]];
int myLength = [[NSMutableString stringWithFormat:@"%@",[arrOutline3 objectAtIndex:countRow]] length];
NSLog(@" the length of dat is :%d",myLength);

int LengthCell;
int LengthCell = myLength /3;
CGFloat heightCell3 ;
int l = LengthCell * 19;
heightCell3 =(CGFloat )l;
NSLog(@" the heigh of cell is :%f",heightCell3 );
countRow = countRow + 1;
return heightCell3;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";

if ((indexPath.row)%2==0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

txtlable1= [[UILabel alloc]initWithFrame:CGRectMake(50, 0, W, H)];
txtlable1.backgroundColor=[UIColor clearColor];
txtlable1.font=[UIFont fontWithName:@"Arial" size:25.0];
txtlable1.text =[arrOutline1 objectAtIndex:count2];
txtlable1.lineBreakMode = UILineBreakModeWordWrap;
txtlable1.textAlignment = UITextAlignmentLeft;
txtlable1.numberOfLines = 0;
[[cell contentView]addSubview:txtlable1];
[txtlable1 release];

txtlable2= [[UILabel alloc]initWithFrame:CGRectMake(600, 0, W-200, H)];
txtlable2.backgroundColor=[UIColor clearColor];
txtlable2.font=[UIFont fontWithName:@"Arial" size:20.0];
txtlable2.textAlignment = UITextAlignmentLeft;
txtlable2.lineBreakMode = UILineBreakModeWordWrap;
txtlable2.numberOfLines = 0;
txtlable2.text =[arrOutline2 objectAtIndex:count2];
[[cell contentView]addSubview:txtlable2];
count2 =count2+1;
[txtlable2 release];
return cell;

}
else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

int myLength = [[NSMutableString stringWithFormat:@"%@",[arrOutline3 objectAtIndex:count1]] length];
NSLog(@" the length of dat is :%d",myLength);
int LengthCell = myLength /3;
CGFloat heightCell3 ;
int l = LengthCell * 15;
heightCell3 =(CGFloat )l;
NSLog(@" the heigh of cell is :%f",heightCell3 );

txtlable3=[[UILabel alloc]initWithFrame:CGRectMake(50,0,W+400,heightCell3)];
txtlable3.backgroundColor=[UIColor clearColor];

txtlable3.font=[UIFont fontWithName:@"Arial" size:30.0];
txtlable3.lineBreakMode = UILineBreakModeWordWrap;
txtlable3.numberOfLines = 0;

txtlable3.text =[arrOutline3 objectAtIndex:count1];
[cell addSubview:txtlable3];
count1 = count1 + 1;

return cell;
}
}

- (void)viewDidLoad {
[super viewDidLoad];
arrOutline1 = [[NSMutableArray alloc]initWithObjects:@"vijay sankar ramamknkakjdkl.\n the thinking the main. candidate of things thisisingamaldaj",@"Amith",@"Gupta",@"RightData",@"RightData1",@"RightData2",@"RightData3",@"RightData4",@"RightData5",@"RightData6",nil];
arrOutline2 = [[NSMutableArray alloc]initWithObjects:@"ganesh",@"surya",@"sudha",@"LeftData",@"LeftData1",@"LeftData2",@"LeftData3",@"LeftData4",@"LeftData5",@"LeftData6",nil];
arrOutline3 = [[NSMutableArray alloc]initWithObjects:@"vijay sankar ramamknkakjdkl.\n the thinking the main.\n candidate of things thisisingamaldaj .\n ",@"jagadish",@"night fhdfhda fhadfhadf.\n dfafhdjkahfa",@"3rdData",@"3rdData1 .\n vijay sankar ramamknkakjdkl.\n the thinking the main.\n candidate of things thisisingamaldaj",@"3rdData2",@"3rdData3",@"3rdData4",@"3rdData5",@"3rdData6 3rdData1 .\n vijay sankar ramamknkakjdkl.\n the thinking the main.3rdData1 .\n vijay sankar ramamknkakjdkl.\n the thinking the main.3rdData1 .\n vijay sankar ramamknkakjdkl.\n the thinking the main.",nil];

CGFloat heihtTable;
heihtTable =[arrOutline1 count] + [arrOutline3 count] ;
heihtTable =heihtTable *175 ;
scrl.contentSize=CGSizeMake(728,heihtTable);
count1=0;
count2=0;
countRow =0;
lblCompetency = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 400, 100)];
lblCompetency.text = @"Competency";
lblCompetency.font = [UIFont fontWithName:@"Helvetica" size: 24.0];
[self.scrl addSubview:lblCompetency];

NSLog(@"The height is %f",heihtTable);
TableOutline = [[UITableView alloc] initWithFrame:CGRectMake(10, 150,1000,heihtTable) style:UITableViewStyleGrouped];
TableOutline.separatorColor=[UIColor blackColor];
TableOutline.backgroundColor=[UIColor clearColor];
[TableOutline setUserInteractionEnabled:NO];
TableOutline.opaque=YES;
TableOutline.delegate =self;
TableOutline.dataSource = self;
TableOutline.allowsSelection=FALSE;

UIView *viewTable2=[[UIView alloc]initWithFrame:CGRectMake(10, 200, 1000, heihtTable)];
viewTable2.backgroundColor=[UIColor clearColor];
TableOutline.backgroundView =viewTable2;
[self.scrl addSubview:TableOutline];
}

最佳答案

您可能可以尝试委托(delegate)方法:

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath

并根据indexpath指定cell参数的高度。

关于iphone - 如何动态更改tableview ipad中的行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6993728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com