Iphone UITableViewCell iOS6
我有一个项目(AppDelegate、ViewController和UITableViewCell) //ViewController.m(节选) //TableCell.m(UITableViewCell类)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
警告(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