-1

我有项目(AppDelegate、ViewController 和 UITableViewCell)。

//ViewController.m(摘录)

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

TableCell *cell = (TableCell *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//====A====
    cell = [[TableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];

    //====B==== //cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    UIView *bgView = [[UILabel alloc] initWithFrame:CGRectZero];
    cell.backgroundView = bgView;

    for(UIView *view in cell.contentView.subviews){
        view.backgroundColor = [UIColor clearColor];
    }
}

cell.titleLabel.text = [NSString stringWithFormat:@"%@ %i", @"row", indexPath.row];

if(indexPath.row % 2){
    cell.backgroundView.backgroundColor = [UIColor whiteColor];
}else{
    cell.backgroundView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.1];
}

return cell;
}

//TableCell.m(UITableViewCell 类)

  #import "TableCell.h"

NSString *CellIdentifier = @"CellIdentifier";

@implementation TableCell

@synthesize titleLabel;

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
    {

        titleLabel = [[UILabel alloc] initWithFrame:frame];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.frame = CGRectMake(10.0, 0.0, 320.0, 40.0);
        [self.contentView addSubview:titleLabel];
        self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }

    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end

warning(initWithFrame:...iOS3)在 //===A=== 部分中生成。因此我写 //===B===。牢房里什么都没有。我想摆脱警告。

4

1 回答 1

0

initWithFrame:reuseIdentifier:是自 iOS 3.0 以来已弃用的方法(很多时间)。使用较新initWithStyle:reuseIdentifier:的,警告就会消失。

UITableViewCell 文档

于 2013-06-17T14:17:03.570 回答