Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UITableView创建4个正方形_Objective C_Ios_Xcode_Uitableview - Fatal编程技术网

Objective c UITableView创建4个正方形

Objective c UITableView创建4个正方形,objective-c,ios,xcode,uitableview,Objective C,Ios,Xcode,Uitableview,我想用UITableView创建日历视图 我希望每行有4个正方形,如下图所示: 你能帮我一下吗?我怎么能在桌子上有一排4个正方形 我知道如何创建具有不同剖面和行的动态表格视图,但如何在一行中创建4个正方形 提前谢谢 Edit1:viewDidLoad中的我的代码: - (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *keys = [[NSMutableArray alloc] init]; NSMutableDictionary

我想用UITableView创建日历视图

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

你能帮我一下吗?我怎么能在桌子上有一排4个正方形 我知道如何创建具有不同剖面和行的动态表格视图,但如何在一行中创建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
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
int列=4;

对于(int i=0;i如果您想要创建日历视图,请查看一些想法(取决于您想要实现的目标)

要创建一个包含四个大小相等的单元格的
UITableView
行,只需实现
tableView:cellforrowatinexpath:
datasource方法来创建一个包含四个大小相等的
UILabel
s的视图。

尝试以下代码:-

- (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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero]autorelease];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
int列=4;

对于(int i=0;我想请您通过示例让我知道如何在uitableview中一行创建4个单元格我不知道该怎么做,
uitableview
中的每一行都是一个单元格。每行不能有多个单元格,但每个单元格可以包含任意数量的视图。只需使用
addSubview:
向每个单元格添加多个视图即可(=行)。它表示使用未声明的标识符。只需在
cellForRowAtIndexPath
方法中将int column=4置于此代码段上方。4表示要在tableview中的单行中放置的列数。这应该只是单元格标识符。请确保已定义传递给
dequeueReusableCellWithIdentifier:
的字符串,也就是说,
静态NSString*cellIdentifier=@“CellId”;UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
@ErenBeşel现在我没有任何错误,但我如何测试它,因为我运行programm@ErenBe我该不该在我的视野里做点什么?