首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView创建4平方

UITableView创建4平方
EN

Stack Overflow用户
提问于 2012-07-30 09:11:28
回答 2查看 388关注 0票数 0

我想用UITableView创建日历视图

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

请你帮我一下,我怎么能在一排中有4个正方形,我知道如何创建不同的部分和行的动态表视图,但是如何在一排中有4个正方形呢?

提前感谢!

Edit1 :我在viewDidLoad :中的代码

代码语言:javascript
复制
 - (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;
}

My Code in cellForRowAtIndexPath

代码语言:javascript
复制
- (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;
}
EN

回答 2

Stack Overflow用户

发布于 2012-07-30 11:05:16

试试这个代码:-

代码语言:javascript
复制
- (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
EN

Stack Overflow用户

发布于 2012-07-30 09:25:56

如果您想要创建一个日历视图,请查看这段代码中的一些想法(取决于您想要实现的目标)。

要创建一个具有四个大小相等的单元格的UITableView行,只需实现tableView:cellForRowAtIndexPath:数据源方法来创建一个视图,例如,四个大小相等的UILabel

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11718414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档