我的自定义单元格当前显示不正确(彼此重叠且没有背景):
我的TableViewController目前配置如下:
#import "EditExerciseTableViewController.h"
#import "ExerciseSetCell.h"
@interface EditExerciseTableViewController ()
@end
@implementation EditExerciseTableViewController
static NSString *CellIdentifier = @"ExerciseSetCell";
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"ExerciseSetCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
self.title = _routineExercise.exercise.name;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_routineExercise.sets count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ExerciseSetCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[ExerciseSetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.setNumberTextLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row + 1];
return cell;
}
@end
有什么想法吗?
编辑似乎是iOS 8 / XCode 6 beta 6中的错误
答案 0 :(得分:1)
试试这个。希望它能帮到你。并从中删除此行[self.tableView registerNib:[UINib nibWithNibName:@"ExerciseSetCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
viewDidLoad中。还会导入自定义单元格文件#import"ExerciseSetCell.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"ExerciseSetCell";
ExerciseSetCell *cell = (ExerciseSetCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExerciseSetCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.setNumberTextLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row + 1];
return cell;
}