Jas*_*son 9 iphone cocoa-touch objective-c cs193p uitableview
我似乎无法让文本实际跨越多行.高度看起来正确.我错过了什么?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"StatusCell"] autorelease];
CGRect frame = cell.contentView.bounds;
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
myLabel.text = [[person.updates objectAtIndex:indexPath.row] valueForKey:@"text"];
[cell.contentView addSubview:myLabel];
[myLabel release];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *text = [[person.updates objectAtIndex:indexPath.row] valueForKey:@"text"];
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize withinSize = CGSizeMake(tableView.frame.size.width, 1000);
CGSize size = [text sizeWithFont:font constrainedToSize:withinSize lineBreakMode:UILineBreakModeWordWrap];
return size.height + 20;
}
Run Code Online (Sandbox Code Playgroud)
另外,我错过了哪些标签看起来比表格单元格更长? 替代文字http://i31.tinypic.com/15chnjd.gif
not*_*oop 15
Tweetero提供了一个例子MessageListController.m.那里的代码呈现以下屏幕:
http://ec.mashable.com/wp-content/uploads/2009/04/imageshackscreen.jpg
(Pic取自Mashable).
基本实施大纲:
构建a时UITableViewCell,UILabel按照中所示的方式创建并添加a 作为子视图tableviewCellWithReuseIdentifier:.寻找TEXT_TAG标签的创建.
在丰富UITableViewCellwith视图时,确保正确地格式化标签,如同所做configureCell:forIndexPath,同样寻找标签标签TEXT_TAG.
返回每个单元格的适当高度,如下所示tableView:heightForRowAtIndexPath.
| 归档时间: |
|
| 查看次数: |
6382 次 |
| 最近记录: |