在我的项目中,我收到了一个弃用警告,initWithFrame : reuseIdentifier : is deprecated
我不知道这是什么意思,有人能告诉我如何解决这个警告吗?谢谢
下面是简短的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue = [itemsList objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}警告就在那一行上:
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];发布于 2011-08-06 22:40:05
Take a look at this Apple's page
此处红色突出显示的功能和属性将在未来由苹果在即将到来的软件开发工具包中删除。
,这样我们在创建App.时就应该避免它们
,因为我们需要长期的项目,这应该运行没有崩溃。
不推荐使用的方法意味着它已被替换/停用,但在当前版本的语言中仍然有效。应该避免它,并且它可能会导致问题/错误。请查看文档,其中应列出您可以使用的替代方法。
在这里,您应该使用方法
- initWithStyle:reuseIdentifier: 那么您的if循环将如下所示
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}发布于 2012-08-27 22:43:11
这个问题出现在Mark,Nutting和La Marche的Beginning 5开发中。有些读者可能来自那本书,在那本书中,265页出现了过时的代码。他们可能会认为这是他们的错!
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: sectionsTableIdentifier] autorelease];需要替换为(正如上面的贡献者指出的那样)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: sectionsTableIdentifier];请注意,我也删除了自动释放,因为自动引用计数不喜欢它!
希望这能有所帮助。
发布于 2012-06-06 17:31:05
使用以下代码:
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];https://stackoverflow.com/questions/6967506
复制相似问题