在iOS7中,使用UITableView的时候,对于cell要注意:[cell addSubview:textField] ;
这种用法不能再用了,应该使用 [cell.contentView addSubview:textField] 的方式。
UITableViewCell的定制
以前可以直接继承UITableViewCell然后drawRect 可以实现定制;
现在的UITableViewCell包含了一个scrollView,你重绘了UITableViewCell将会被这个scrollView遮住而完全没法显示,或者 drawRect 的方法里面用cell.contentView添加控件;
这种用法不能再用了,应该使用 [cell.contentView addSubview:textField] 的方式。
UITableViewCell的定制
以前可以直接继承UITableViewCell然后drawRect 可以实现定制;
现在的UITableViewCell包含了一个scrollView,你重绘了UITableViewCell将会被这个scrollView遮住而完全没法显示,或者 drawRect 的方法里面用cell.contentView添加控件;
【解决方案]:(ARC文件)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify = @"UITableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if(cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
UIView * subview = [[UIView alloc] init];
subview.userInteractionEnabled = NO;
subview.backgroundColor = [UIColor clearColor]; // 设为透明
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:subview];// cell.contentView是个readonly属性.return cell;
}