I found so many tutorials on how to create custom table view cell using XIB, but is it possible to create custom table view cell without using XIB? Can some one help me?
Yeah, You can create Custom table view cell without using a XIB.
For this, you have to create one new class in Xcode with the subclass of UITableViewCell. here you can't select any XIB options.
Now open your custom UITableViewCell class and here's code that will achieve what you want:
#import "CustomCell.h"
@implementation CustomCell
@synthesize ivUser;
@synthesize lblUserName;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:
(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
ivUser = [[UIImageView alloc] initWithFrame:CGRectMake(4.0f, 3.0f, 39.0f,
38.0f)];
lblUserName = [[UILabel alloc] initWithFrame:CGRectMake(58.0f, 8.0f, 50.0f,
27.0f)];
[self.contentView addSubview:ivUser];
[self.contentView addSubview:lblUserName];
}
return self;
}
Now set your subviews coordinates according to the requirement, then use this cell in your CellForRowAtIndexPath and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With