ritch
ritch

Reputation: 1808

Custom XIB UITableViewCell not displaying correctly

My custom cell is currently displaying incorrectly (there on top of each other and with no background):

enter image description here

My TableViewController is currently configured like this:

#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

Any ideas?

EDIT Appears to be a bug in iOS 8/XCode 6 beta 6

Upvotes: 1

Views: 264

Answers (1)

Mohit
Mohit

Reputation: 3416

Try this. Hope it will helps you. and remove this line [self.tableView registerNib:[UINib nibWithNibName:@"ExerciseSetCell" bundle:nil] forCellReuseIdentifier:CellIdentifier]; from viewDidLoad. also import your custom cell file #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;
}

Upvotes: 0

Related Questions