2 iphone cocoa-touch objective-c
我试图阅读一些RSS数据.我有不同大小的数据.数据存在于tabke视图数据对象中.我使用标签添加数据并调整数据大小.没有成功.请帮忙.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSLog(@"in the tabel view cell");
heightOfCell=[self tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Default"];
if (cell == nil)
{
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,heightOfCell) reuseIdentifier:@"Default"] autorelease];
UILabel *label = [[UILabel alloc] init];
NSString *cellText = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:10.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
label.text = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
CGSize labelSize = [[[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]] sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
label.lineBreakMode=UILineBreakModeWordWrap;
[label sizeThatFits:labelSize];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,heightOfCell) reuseIdentifier:@"Default"] autorelease];
//[label sizeToFit];
[cell addSubview:label];
[label release];
}
}
Run Code Online (Sandbox Code Playgroud)
dar*_*han 24
您需要使用以下方法.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 45;
}
Run Code Online (Sandbox Code Playgroud)
你需要根据你的要求改变高度
应该注意的是,默认高度是44.
| 归档时间: |
|
| 查看次数: |
21834 次 |
| 最近记录: |