Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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
Iphone UITableViewCell iOS6_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone UITableViewCell iOS6

Iphone UITableViewCell iOS6,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有一个项目(AppDelegate、ViewController和UITableViewCell) //ViewController.m(节选) //TableCell.m(UITableViewCell类) 警告(initWithFrame:…iOS3)在部件中生成//==A==。因此,我写//==B==。牢房里什么也没有。 我想摆脱警告 initWithFrame:reuseIdentifier:是自iOS 3.0以来被弃用的方法(很多时候)。使用较新的initWithStyle:reus

我有一个项目(AppDelegate、ViewController和UITableViewCell)

//ViewController.m(节选)

//TableCell.m(UITableViewCell类)

警告(initWithFrame:…iOS3)
在部件中生成//==A==。因此,我写//==B==。牢房里什么也没有。
我想摆脱警告

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


重写
initWithStyle:reuseIdentifier:
而不是
initWithFrame:reuseIdentifier:
并使用前者创建单元格。覆盖
layoutSubviews
以定位单元格内容。不需要设置表格视图单元格的框架。这一部分是由datasource方法完成的。如果我只使用reuseIdentifier:,则可以。谢谢
 - (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;
}
  #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