2
A
回答
0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
// load cell from nib to controller's IBOutlet
[[NSBundle mainBundle] loadNibNamed:@"MyTableCellView" owner:self options:nil];
// assign IBOutlet to cell
cell = myCell;
self.myCell = nil;
}
id modelObject = [myModel objectAtIndex:[indexPath.row]];
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = [modelObject firstField];
label = (UILabel *)[cell viewWithTag:2];
label.text = [modelObject secondField];
label = (UILabel *)[cell viewWithTag:3];
label.text = [modelObject thirdField];
return cell;
}
我认为这个代码将会帮助你UITableView并不是真正为m设计的多个列。但是你可以通过创建一个自定义的UITableCell类来模拟列。在Interface Builder中构建自定义单元格,为每列添加元素。给每个元素一个标签,以便您可以在控制器中引用它。
给您的控制器的插座从笔尖加载细胞:
@property(nonatomic,retain)IBOutlet UITableViewCell *myCell;
然后,在你表视图委托的的cellForRowAtIndexPath方法中,通过标签分配这些值。
2
这是我做的:
#import <Foundation/Foundation.h>
@interface MyTableCell : UITableViewCell
{
NSMutableArray *columns;
}
- (void)addColumn:(CGFloat)position;
@end
实现:
#import "MyTableCell.h"
#define LINE_WIDTH 0.25
@implementation MyTableCell
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (void)addColumn:(CGFloat)position
{
[columns addObject:[NSNumber numberWithFloat:position]];
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Use the same color and width as the default cell separator for now
CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
CGContextSetLineWidth(ctx, LINE_WIDTH);
for (int i = 0; i < [columns count]; i++)
{
CGFloat f = [((NSNumber*) [columns objectAtIndex:i]) floatValue];
CGContextMoveToPoint(ctx, f, 0);
CGContextAddLineToPoint(ctx, f, self.bounds.size.height);
}
CGContextStrokePath(ctx);
[super drawRect:rect];
}
@end
和最后一块,的cellForRowAtIndexPath
MyTableCell *cell = (MyTableCell *)[rankingTableView dequeueReusableCellWithIdentifier:MyIdentifier];
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
相关问题
- 1. 如何创建具有两行和多列的水平GridView
- 2. 如何创建具有多个列
- 3. 如何创建具有多列钛表中的行的表格?
- 4. 如何创建具有多个视图的列表行项目
- 5. 如何创建多节的tableView
- 6. TableView具有比指定更多的列
- 7. 如何创建具有多个域
- 8. 如何将具有多列的行转换为具有两列(字段名和值)和多行的表?
- 9. IOS如何用两列第一列创建tableview有一行,第二列有多行?
- 10. 从TableView创建多个Segges
- 11. 如何在iPhone SDK中创建具有多列结构和水平滚动的tableView?
- 12. 创建具有多个表
- 13. 如何在一行中创建具有多个视图的listView。
- 14. 无法在Android中创建具有标题(列和行)的多个行
- 15. 如何创建多行列表?
- 16. 如何从单列创建多行
- 17. Automapper创建具有多对多关系的新行
- 18. 如何创建多列PK
- 19. 如何创建多列Listbox?
- 20. 如何创建具有不同行为的创建时间列
- 21. 如何创建具有2行和不同列数的表格
- 22. 创建多层数据框 - 行和列
- 23. 创建多个行和列xaml
- 24. 转换具有多个行单列成具有多个列
- 25. 如何创建多行UITextField?
- 26. 如何在Oracle中聚合具有多个列的多行?
- 27. 如何创建具有placeHolder,多行和垂直居中的UITextView或UItextField?
- 28. 将具有多行数据的列转换为Excel中具有多列的行。
- 29. 从多列创建许多行和单列
- 30. 筛选具有多个值的JFX TableView
你应该创建自定义tableviewcell,如果你需要它看起来像多个列 – Buron 2012-04-12 07:08:25
@Buron你会请教关于我的问题的任何教程吗? – kumar 2012-04-12 07:11:22