iPhone开发学习笔记003——UITableViewCell内容自适应高度
的实例,只是将对应的Cell.xib界面换成如下所示:

然后,oneViewController中添加属性:dataArray,即 *.h中添加@property (nonatomic,retain)NSArray *dataArray;
*.m中添加:@synthesize dataArray;
oneViewController.m中的部分代码如下:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.dataArraycount];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CustomCellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell ==nil) {
NSArray *nib = [[NSBundlemainBundle]loadNibNamed:@"Cell"
owner:selfoptions:nil];
// if ([nib count] > 0) {
// cell = self.tableViewCell;
// } else {
// NSLog(@"failed to load CustomCell nib file!");
// }
cell = [nib objectAtIndex:0];
}
NSUInteger row = [indexPathrow];
NSLog(@"++++++++++++++ jonesduan %s, cell row:%d", __func__, row);
UILabel *cellLabel = (UILabel *)[cellviewWithTag:1];
cellLabel.text = [NSStringstringWithFormat:@"cell index %d:", row];
UILabel *contentLabel = (UILabel *)[cellviewWithTag:2];
NSDictionary *rowData = [self.dataArrayobjectAtIndex:row];
//设置自动行数与字符换行
[contentLabel setNumberOfLines:0];
contentLabel.lineBreakMode =UILineBreakModeWordWrap;
UIFont *font = [UIFontfontWithName:@"Arial"size:12];
//设置一个行高上限
//CGSize size = CGSizeMake(100 /*nameLabel.frame.size.width*/, 2000);
CGSize size = CGSizeMake(100,2000); // 这里不一定就得是100和2000,具体数字是自已试出来的,这里的修改会影响下面计算出来的labelsize ,望牛人指教此处两个参数应该如何确定具体值,即能够通过计算一次得出应该设置的值???
NSLog(@"nameLabel(x, y, witdh, height) = (%f, %f, %f, %f)", contentLabel.frame.origin.x, contentLabel.frame.origin.y, contentLabel.frame.size.width, contentLabel.frame.size.height);
NSLog(@"size(width, height) = (%f, %f)", size.width, size.height);
NSString *labelText = [rowDataobjectForKey:@"Name"];
//计
相关新闻>>
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
- iPhone开发学习笔记004——自定义背景透明非全屏弹出窗口,子类化UIWindow
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller
- iPhone开发学习笔记006—— NSNotification自定义通知名
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用
- iPhone开发学习笔记008——定制标题三种方法
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- iPhone应用开发之十一:常用的三种动画表现效果
- iPhone开发学习笔记006—— NSNotification自定义通知名
- 多线程之NSInvocationOperation
- Lexical or Preprocessor Issue 'xxx.h
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- Memory on the iPhone
- ios开发问题:添加库和复制其它工程文件编译错误问题
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- Android:实现TabWidget选项卡按钮在屏幕下方
- iphone开发之object c基础一定义接口