UITableView创build4个方块

我想用UITableView创build日历视图

我想在每一行有4个方格,如下图所示:

你能帮我吗,我怎么能在表中的一行4平方我知道我怎么能创build不同的部分和行的dynamic表视图,但我怎样才能在一行4平方?

提前致谢!

编辑1:我在viewDidLoad中的代码:

- (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *keys = [[NSMutableArray alloc] init]; NSMutableDictionary *contents = [[NSMutableDictionary alloc] init]; NSString *monKey = @"Monday"; NSString *tueKey = @"Tuesday"; NSString *wedKey = @"Wednday"; NSString *thuKey = @"Thusday"; NSString *friKey = @"Friday"; NSString *satKey = @"Satuarday"; NSString *sunKey = @"Sunnday"; [contents setObject:[NSArray arrayWithObjects:@"Work Time", @"Absence", nil] forKey:monKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", @"Absence", nil] forKey:wedKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", nil] forKey:tueKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", nil] forKey:thuKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", nil] forKey:friKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", nil] forKey:satKey]; [contents setObject:[NSArray arrayWithObjects:@"Compensation", @"Work Time", nil] forKey:sunKey]; [keys addObject:tueKey]; [keys addObject:monKey]; [keys addObject:wedKey]; [keys addObject:thuKey]; [keys addObject:friKey]; [keys addObject:satKey]; [keys addObject:sunKey]; [self setSectionKeys:keys]; [self setSectionContents:contents]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. self.navigationItem.leftBarButtonItem = self.editButtonItem; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem)]; self.navigationItem.rightBarButtonItem = rightButton; } 

我的代码在cellForRowAtIndexPath

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame:CGRectZero]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; int column = 4; for (int i=0; i<column; i++) { UIImageView *aBackgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(32+184*i,10, 167,215)]; aBackgroundImageView.tag = (column*indexPath.row)+i; [cell.contentView addSubview:aBackgroundImageView]; // [aBackgroundImageView release]; } return cell; } 

试试这个代码:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; int column = 4; for (int i=0; i<column; i++) { UIImageView *aBackgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(32+184*i,10, 167,215)]; aBackgroundImageView.tag = (column*indexPath.row)+i; [cell.contentView addSubview:aBackgroundImageView]; [aBackgroundImageView release]; } return cell; } 

列将在一个单元格中所需的项目数量。

如果你想创build一个日历视图,请查看这个代码的一些想法(取决于你想实现的)。

要创build一个具有四个相同大小的单元格的UITableView行,只需实现tableView:cellForRowAtIndexPath: datasource方法来创build一个具有四个相同大小的UILabel的视图。