Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Custom table cell not full width of UITableView

I may be going about this wrong. So I have created a UITableView that essentially has a auto-layout trailing space set to the main view. I am creating a custom cell for this table so I drug on a prototype cell, customized it, and created my class for it. That is all working just fine.

What I can't seem to solve is the custom cell isn't going the full width of the actual table cell so a white background just shows up. If I don't use the custom cell the entire width table cell gets utilized.

I set the constraints for the cell content so that the background image should fill the cell.

What am I doing wrong? Let me know what you need to help solve this.

ProfileCustomCell.h

#import <UIKit/UIKit.h>

@interface ProfileCustomCell : UITableViewCell {

}

@property (nonatomic, strong) IBOutlet UILabel *nameLabel;
@property (nonatomic, strong) IBOutlet UIImageView *profileImageView;

@end

ProfileCustomCell.m

#import "ProfileCustomCell.h"

@implementation ProfileCustomCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {
        self.nameLabel.text = nil;
    }

    return self;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end

UITableView

[tableView registerNib:[UINib nibWithNibName:@"ProfileCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Cell"];

[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

ProfileCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

cell.nameLabel.text = [NSString stringWithFormat:@"%@", [child objectForKey:@"first_name"]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

enter image description here

like image 264
Josh York Avatar asked Jun 04 '15 02:06

Josh York


3 Answers

Can you post the code please .

Did you enable the Use Auto layout and Use Size Classes as below do that first in both table view and table view cell .and tell me your problem

enter image description here

1)After that select both image and label and do as below

enter image description here

2) Select the image and do below

enter image description here

3) select the label an do the following

enter image description here

Can you check the link below:

Table cell content(title) moving left after selecting cell

like image 54
Nischal Hada Avatar answered Oct 21 '22 05:10

Nischal Hada


Instead of "filling", auto layout constraints to leading and trailing space to constant 0 and make sure they're not relative to margins.

like image 1
Profezy Avatar answered Oct 21 '22 06:10

Profezy


select your table view cell's connection inspector and check if you haven't connected editingAccessoryView by mistake

enter image description here

like image 1
Milap Kundalia Avatar answered Oct 21 '22 05:10

Milap Kundalia