gpt4 book ai didi

objective-c - UITableView创建4个正方形

转载 作者:行者123 更新时间:2023-11-29 04:31:16 26 4
gpt4 key购买 nike

我想用 UITableView 创建日历 View

我想每行有 4 个正方形,如下图所示:

请你帮帮我,我怎样才能在表格中排成一行4个正方形我知道如何创建具有不同部分和行的动态表格 View ,但如何在一排中有 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;
}

最佳答案

试试这个代码:-

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

列将在一个单元格中显示您想要的项目数。

关于objective-c - UITableView创建4个正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com