今天在调试 cell 用 xib 文件的时候发现,调试了很长时间 发现 在 6 之上时可以用,在 6之下时不可以用会报错
使用:
static NSString *CellIndentifier = @"RightTableViewCell";
/ RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//
// static NSString *CellIndentifier = @"RightTableViewCell";
// RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//
// if (cell == nil) {
// cell = [[[RightTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
// }
在6.1上可以用,在6之下发现之下错误:
经过调试 使用
static NSString *CellIndentifier = @"RightTableViewCell";
RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
if(cell==nil)
{
NSArray *nibsArray=[[NSBundle mainBundle] loadNibNamed:@"RightTableViewCell" owner:self options:nil];
cell=(RightTableViewCell*)[nibsArray objectAtIndex:0];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndentifier = @"RightTableViewCell";
RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
if(cell==nil)
{
NSArray *nibsArray=[[NSBundle mainBundle] loadNibNamed:@"RightTableViewCell" owner:self options:nil];
cell=(RightTableViewCell*)[nibsArray objectAtIndex:0];
}
//下边这个只可以目前 自己尝试 只可以 用在 6 之上
// RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//
// static NSString *CellIndentifier = @"RightTableViewCell";
// RightTableViewCell *cell = (RightTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//
// if (cell == nil) {
// cell = [[[RightTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
// }
[cell setBackgroundImage:nil];
NSString *tag = @"";
if (indexPath.section == 0) {
tag = [tagList count] == 0 ? @"" : [tagList objectAtIndex:indexPath.row];
}
NSString *imageFileName = @"tag.png";
[cell setIcon:[UIImage imageNamed:imageFileName]];
NSLog(@"----------- %@",tag);
[cell setName:tag];
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.frame];
backgroundView.backgroundColor = TAG_SELECTED_BACKGROUND;
cell.selectedBackgroundView = backgroundView;
[backgroundView release];
return cell;
}
需要设置:
在 Interface Builder 里点击打开ViewController.xib。在你做任何其他事情之前,请先在nib里把Auto Layout禁用掉。你可以在File inspector里找到这个选项:
取消选择“Use Autolayout”复选框. 那么现在你的nib使用的是旧版本的 struts-and-springs 模式。
提示: 任何你通过Xcode4.5或者更高版本创建的新nib或者storyboard文件会默认使用Auto Layout。因为Auto Layout这个特性只有在IOS 6中有,所以如果你想要使用 Xcode4.5来做一些兼容IOS5的应用,你必须要在新的nib或者storyboard文件中通过取消选择“Use Autolayout”复选框来禁用Auto Layout。