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