0

UITableViewでカレンダービューを作成したい

次の図のように、各行に4つの正方形が必要です。

助けていただけませんか。テーブルの1行に4つの正方形を配置するにはどうすればよいですか。さまざまなセクションと行を使用して動的なテーブルビューを作成する方法を知っていますが、1行に4つの正方形を配置するにはどうすればよいですか。

前もって感謝します!

Edit1: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;
}
4

2 に答える 2

1

このコードを試してください:-

- (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;
}

列は、1 つのセルに必要な項目の数になります。

于 2012-07-30T11:05:16.203 に答える
0

カレンダー ビューを作成する場合は、このコードを参照してアイデアを確認してください (目的に応じて異なります)。

UITableView同じサイズの 4 つのセルを含む行を作成するには、 tableView:cellForRowAtIndexPath:datasource メソッドを実装して、たとえば同じサイズUILabelの 4 つの を含むビューを作成します。

于 2012-07-30T09:25:56.147 に答える