Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 如何修复:initWithFrame:CellFrame reuseIdentifier:cellIdentifier已弃用_Objective C_Deprecated_Xcode4.2_Initwithstyle - Fatal编程技术网

Objective c 如何修复:initWithFrame:CellFrame reuseIdentifier:cellIdentifier已弃用

Objective c 如何修复:initWithFrame:CellFrame reuseIdentifier:cellIdentifier已弃用,objective-c,deprecated,xcode4.2,initwithstyle,Objective C,Deprecated,Xcode4.2,Initwithstyle,我升级到XCODE 4.2,突然收到了所有这些警告信号。大多数问题我都能解决,但以下问题我不知道如何解决。我试着读了一遍,但还是有问题 不推荐使用的代码是: UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease]; 我知道我需要使用以下工具: - (id)initWithStyle:(UITableViewCell

我升级到XCODE 4.2,突然收到了所有这些警告信号。大多数问题我都能解决,但以下问题我不知道如何解决。我试着读了一遍,但还是有问题

不推荐使用的代码是:

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
我知道我需要使用以下工具:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
然而,当我测试时,我遇到了细胞框架等问题

有人能给我一个提示,我应该如何用initWithStyle替换不推荐使用的代码并得到相同的结果吗

以下是完整的代码:

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(30, 33, 270, 25);
CGRect Label3Frame = CGRectMake(30, 56, 270, 25);
UILabel *lblTemp;

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];

//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.3f alpha:1.0f];
lblTemp.textColor = [UIColor whiteColor];
lblTemp.backgroundColor = [UIColor clearColor];
[lblTemp setFont:[UIFont fontWithName:@"American Typewriter" size:16]];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];

//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.3f alpha:1.0f];
lblTemp.tag = 2;
[lblTemp setFont:[UIFont fontWithName:@"American Typewriter" size:13]];
lblTemp.textColor = [UIColor whiteColor];
lblTemp.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];

//Initialize Label with tag 3.
lblTemp = [[UILabel alloc] initWithFrame:Label3Frame];
lblTemp.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.3f alpha:1.0f];
lblTemp.tag = 3;
[lblTemp setFont:[UIFont fontWithName:@"American Typewriter" size:13]];
lblTemp.textColor = [UIColor whiteColor];
lblTemp.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];

return cell;
}

刚开始用style初始化,然后设置reuired frame。我看不出有任何问题:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.frame = CellFrame;
    }

类似的东西

 cell = [[[UITableViewCell alloc] initWithStyle:somestyle reuseIdentifier:@"cellname"] autorelease]
 cell.frame = cellFrame;
我不确定你是否真的需要设置单元格框,除非你想要一些特定的框,它应该设置为tableview的任何值。

我只使用这段代码
cell=[[customCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]

向我们展示您尝试使用initWithStyle的代码,并向我们展示您遇到的错误。我得到:Class方法“+dequeueReusableCellWithIdentifier:”找不到(返回类型默认为“id”)
dequeueReusableCellWithIdentifier
是UITableView方法。请您建议我如何解决上述代码中的问题?抱歉,你问最后一个问题时,我已经睡着了。这是一篇很好的文章,有很多例子-。我建议你读一整本指南。
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
{
         cell  = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
} 
return cell;
}