Resizing properties in custom cell for UITableView - objective-c

I have a UITableView with a custom cell and its corresponding .xib.
My CustomCell.h has 3 properties. I want to be able to specify the width of these properties programmatically without using auto layout. The three properties are a background image, a header view, and a title within the header view. I want to set the with for all three properties to be the same as the cell.contentView width.
I've place [cell setNeedsLayout] in my cellForRowAtIndexPath but the only property that gets updated is the ImageView and the titleView in CustomCellOne. The with of the label does not get updated. An issue I have with this "solution", aside from the fact that it doesn't update the label width, is that when the cell is displayed I can see the background image width updating. The background image starts at 320 width and expands to 375 width. I want the layoutSubviews to be performed before the cell is displayed.
I've also tried placing [cell setNeedsLayout] inside willDisplayCell but it produces the same behavior mentioned above.
I've also tried [self setNeedsLayout] in the awakeFromNib method from CustomCellOne.m but that also produces the same result mentioned above.
This custom cell needs to be able to take into account the dimensions of the different iPhone sizes and [ImageManager] returns the appropriate background image for the specific device.
If I select the cell then the layoutSubviews will update as I want them to be. Is there a way to trigger programmatically the selection of a cell? This would not be the preferable solution since it's a hack and I'm sure there's a better way, the right way, to do what I want.
I will be forever in the debt of whoever can help me out with this. My code below.
// My ListViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.bounds = [self.view frame];
self.view.backgroundColor = [UIColor colorWithRed:0.882f green:0.902f blue:0.922f alpha:1.00f];
[self setNeedsStatusBarAppearanceUpdate];
// Setup the table view
self.tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
// Setup the bar
self.myCustomBar = [[StyleOneBar alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.bounds), 100.0)];
SquareCashStyleBehaviorDefiner *behaviorDefiner = [[SquareCashStyleBehaviorDefiner alloc] init];
behaviorDefiner.elasticMaximumHeightAtTop = YES;
[behaviorDefiner addSnappingPositionProgress:0.0 forProgressRangeStart:0.0 end:0.5];
[behaviorDefiner addSnappingPositionProgress:1.0 forProgressRangeStart:0.5 end:1.0];
behaviorDefiner.snappingEnabled = YES;
self.myCustomBar.behaviorDefiner = behaviorDefiner;
[self.view addSubview:self.myCustomBar];
// Configure a separate UITableViewDelegate and UIScrollViewDelegate (optional)
self.delegateSplitter = [[BLKDelegateSplitter alloc] initWithFirstDelegate:behaviorDefiner secondDelegate:self];
self.tableView.delegate = (id<UITableViewDelegate>)self.delegateSplitter;
//[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
self.tableView.contentInset = UIEdgeInsetsMake(self.myCustomBar.maximumBarHeight, 0.0, 0.0, 0.0);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
CustomCellOne *cell = (CustomCellOne *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:#"CustomCellOne" bundle:nil] forCellReuseIdentifier:cellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
NSString *imageName = [NSString stringWithFormat:#"sunbathing%#", [ImageManager getCollectionImagePartialName]];
[cell.ivCategory setImage:[UIImage imageNamed:imageName]];
[cell.lblTitle setText:#"Lazy Beach Day"];
cell.titleView.frame = CGRectMake(0, 0, CGRectGetWidth(cell.contentView.bounds), 29);
return cell;
}
My Custom Cell .h file
// CustomCellOne.h
#import <UIKit/UIKit.h>
#interface EventCellOne : UITableViewCell
#property (strong, nonatomic) IBOutlet UIImageView *ivCategory;
#property (retain, nonatomic) IBOutlet UIView *titleView;
#property (weak, nonatomic) IBOutlet UILabel *lblTitle;
#end
My Custom Cell .m file
#import "CustomCellOne.h"
#import "ImageManager.h"
#implementation EventCellOne
- (void)awakeFromNib
{
// Initialization code
[super awakeFromNib];
self.contentView.backgroundColor = [UIColor clear];
[self setNeedsLayout];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)layoutSubviews
{
[super layoutSubviews];
//self.bounds = self.contentView.bounds;
[ImageManager getCollectionImageHeight]);
CGRect imageViewBounds = CGRectMake(0, 0, [ImageManager getImageMaxWidth], [ImageManager getCollectionImageHeight]);
[self.ivCategory setFrame:imageViewBounds];
self.titleView.frame = CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), 29);
self.titleView.backgroundColor = [UIColor redColor];
self.lblTitle.frame = CGRectMake(3, 4, CGRectGetWidth(self.contentView.bounds)-6, 21);
[self.lblTitle setBackgroundColor:[UIColor lightGrayColor]];
}

Found the solution. I had to uncheck "Use Auto Layout" in IB for the custom cell .xib. My Custom Cell .m file only has layoutSubviews. No need for the drawrect method.
Thank you to #user3654258 with his assistance.

Related

Uislider in a tableView Cell

hi everyone i'm new in iOS programming ! I have a custom table view controller with custom table view cell ! one of those cell have a uislider and a label ! I want to change label text when slider change value ! this is my code :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *cellInfo = [[self.sections objectAtIndex:currentTab] objectAtIndex:indexPath.row];
HLNotificheCell *cell = [tableView dequeueReusableCellWithIdentifier:[cellInfo objectForKey:#"cell"] forIndexPath:indexPath];
UIImageView *radioIndicator = (UIImageView *)[cell.contentView viewWithTag:200];
radioIndicator.image = (currentBullet != indexPath.row) ? [UIImage imageNamed:#"RadioOff"] : [UIImage imageNamed:#"RadioOn"];
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:#"NewsSeparetor.png"];
cell.backgroundView = av;
cell.slider.maximumValue = 100;
cell.slider.minimumValue = 1;
cell.slider.continuous = TRUE;
//set a method which will get called when a slider in a cell changes value
[cell.slider addTarget:self action:#selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
//Keep a reference to each slider by assigning a tag so that we can determine
//which slider is being changed
cell.slider.tag = indexPath.row;
//Grab the value from the sliderValuesArray and set the slider knob to that position
return cell;
}
-(void)sliderChanged:(UISlider*)sender{
HLNotificheCell *cell = [[HLNotificheCell alloc]init];
if (sender == cell.slider) {
cell.label.text = [NSString stringWithFormat:#"%0.3f", cell.slider.value];
}
}
Actually there is a lot of bad practices in your code. Please let me explain.
Let's begin with your HLNotificheCell class. I think header file should look like this:
#import <UIKit/UIKit.h>
#define HLNotificheCellIdentifier #"HLNotificheCellIdentifier"
#interface HLNotificheCell : UITableViewCell
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier;
#property (strong, nonatomic) UISlider *slider;
#property (strong, nonatomic) UIImageView *radioIndicator;
#end
and implementation file:
#import "HLNotificheCell.h"
#implementation HLNotificheCell
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
if (self) {
_slider = [[UISlider alloc] init];
_slider.maximumValue = 100;
_slider.minimumValue = 1;
_slider.continuous = YES; //YES is more natural in objc rather than TRUE.
[self addSubview: _slider];
_radioIndicator = [[UIImageView alloc] init];
[self addSubview:_radioIndicator];
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:#"NewsSeparetor.png"];
self.backgroundView = av;
//it's better to use built-in textLabel instead of creating your own. Trust me when you will have 20 different customized cells you will get lost with their names.
self.textLabel.textColor = [UIColor redColor];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
// layout your self.slider and self.radioIndicator here or use xib for it.
// e.g. this will layout slider to fit whole cell:
self.slider.frame = self.bounds;
}
#end
Ok, lets go now to cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// try to dequeue cell if exist
HLNotificheCell *cell = (HLNotificheCell *)[tableView dequeueReusableCellWithIdentifier:HLNotificheCellIdentifier];
// if doesn't, create new one.
if (!cell) { // is enough to set slider target only once when cell is created. When reuse is not needed.
cell = [[HLNotificheCell alloc] initWithReuseIdentifier:HLNotificheCellIdentifier];
[cell.slider addTarget:self action:#selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
}
//set image as you wish:
cell.radioIndicator.image = (currentBullet != indexPath.row) ? [UIImage imageNamed:#"RadioOff"] : [UIImage imageNamed:#"RadioOn"];
//Keep a reference to each slider by assigning a tag so that we can determine
//which slider is being changed
cell.slider.tag = indexPath.row;
//Grab the value from the sliderValuesArray and set the slider knob to that position
NSNumber *sliderValue = sliderValuesArray[indexPath.row];
[cell.slider setValue:sliderValue.floatValue animated:NO]
return cell;
}
and sliderChanged: method:
-(void)sliderChanged:(UISlider*)sender{
// You cannot do this:
// HLNotificheCell *cell = [[HLNotificheCell alloc]init];
// because you have to restore reference from sender.tag as you wrote in cellForRowAtIndexPath method:
HLNotificheCell *cell = (HLNotificheCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:slider.tag inSection:0]] // I assume you have only 1 section
cell.textLabel.text = [NSString stringWithFormat:#"%0.3f", cell.slider.value];
//save new value to the sliderValuesArray
self.sliderValuesArray[indexPath.row] = #(cell.slider.value);
}
Assumptions:
when you will use this part of code please do not use registerClass:forCellReuseIdentifier:
yours sliderValuesArray is kind of NSMutableArray class.
sliderValuesArray has been initialized with size same as number of cells, like:
self.sliderValuesArray = [[NSMutableArray alloc] initWithCapacity:<#numberOfCels#>];
for (int i = 0; i < sliderValuesArray.count; i++) {
sliderValuesArray[i] = #(0);
}
your table view contains only one type of cells (HLNotificheCell)
There could be some typos and/or lack of semicolons because I wrote it without compiler.
I doing this easier. Apple write that you can use IBActions for static rows. (You can read about it here in The Technique for Static Row Content. But I already tested it on iOS 9 with dynamic cells and it's just works :)
At first - Custom cell with IBAction
#interface SliderTableViewCell ()
#property (weak, nonatomic) IBOutlet UILabel *sliderValueLabel;
#property (weak, nonatomic) IBOutlet UISlider *slider;
#end
#implementation SliderTableViewCell
- (void)awakeFromNib {
self.slider.minimumValue = 1;
self.slider.maximumValue = 1000;
}
- (IBAction)sliderValueChanged:(id)sender {
self.sliderValueLabel.text = [NSString stringWithFormat:#"1_%.f", self.slider.value];
}
#end
Second - TableView Delegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SliderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuseIdentifierSliderCell];
cell.slider.value = 142;
cell.sliderValueLabel.text = #"1_142";
return cell;
}
Third - Run your app and enjoy yourself ;)

UIcollectionview not displaying data.The numberOfItemsInSection and cellForItemAtIndexPath methods are not firing.How to display data on label?

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return departureTimesArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"cell" forIndexPath:indexPath];
User *user = [departureTimesArray objectAtIndex:indexPath.row];
UILabel *label = (UILabel*)[cell.contentView viewWithTag:100];
if (!label)
{
label = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 90.0,90.0, 30.0)];
label.textColor = [UIColor redColor];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.textColor = [UIColor colorWithRed:46.0/255.0 green:63.0/255.0 blue:81.0/255.0 alpha:1.0];
label.tag = 100;
[cell.contentView addSubview:label];
}
// label.text=user.departureTime_Bus;
label.text = [NSString stringWithFormat:#"%#",user.departureTime_Bus];
return cell;
}
Custom delegate method
-(void)repaint:(NSMutableArray *)retrievedData
{
if (retrievedData.count > 0)
{
NSLog(#"%#is the value",retrievedData);
userObj = [retrievedData objectAtIndex:0];
[departureTimesArray addObjectsFromArray:retrievedData];
[mycollectionView reloadItemsAtIndexPaths:departureTimesArray];
}
}
Check first this
#interface ViewController : UIViewController "<"UICollectionViewDelegate,UICollectionViewDataSource">"
Second thing is check IBoutlet
#property (nonatomic, strong) IBOutlet UICollectionView *collectionView;
Third one is check
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
These three step must call for datasource and delegate method of collection view.
If the data source or delegate methods aren't firing, it's usually one of a few things:
Your data source or delegate for the collection view aren't set.
Your collection view is so small that a cell cannot fit in it. Both collection and table views only try to create the number of cells that it can display.
If you're using storyboards, make sure your view controller in the storyboard is actually referencing the file you want it to.

UICollectionView images not showing

I have an issue with the images not showing, even though they are loading. I have tried this several different ways and the same result... no images. I do get white rectangles that are the size and color specified in the Storyboard. I get the correct number of rectangles in the popover. The log shows the names and ids correctly.
If I call the array directly, I get the same result... white rectangles.
My target is iOS7. Running Xcode 5.0.2. Images are coming from a SQL database. This is a live app, which I am updating to full iOS7 and where I am swapping out a custom grid layout for UICollectionView. Using a CollectionViewController, embedded into a NavigationController, which is accessed via a UIButton. As you can see, there is no custom cell. The images are to show in a popover and are then selectable by the user to change the background of the underlying view.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
NSLog(#"Filename: %#", tempImage);
NSLog(#"ButtonTagNumber: %#", buttonTagNumber);
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:tempImage];
NSLog(#"Image.image: %#", image.image);
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The fix which includes actually naming the BackgroundCell (duh) in the cellForItemAtIndexPath method and creating a small method in the BackgroundCell controller to set the image.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
[cell setImage:[UIImage imageNamed:tempImage]];
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The main cell code;
- (id)initWithFrame:(CGRect)frame
{
_backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_backgroundImage];
if (self) {
// Initialization code
}
return self;
}
-(void)setImage:(UIImage *)image
{
_backgroundImage.image = image;
}
The problem is that the image is not being set in the cell's view hierarchy. To do that, subclass UICollectionViewCell and create a imageView property in the subclass:
#interface CollectionViewCellSubclass : UICollectionViewCell
#property (nonatomic, strong) UIImageView *imageView;
#end
...and init the UIImageView in its initWithFrame:
_imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_imageView];
Set this subclass as the Custom Class for the cell in storyboard and then load it in the collectionView:cellForItemAtIndexPath method above setting the image to the cell's image subview:
CollectionViewCellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
//...
cell.imageView.image = [UIImage imageNamed:tempImage];
Hope this helps.
Adding cell.contentView.frame = [cell bounds] after the line dequeueReusableCellWithReuseIdentifier worked for me.
Suppose you add a custom (200,200) UICollectionViewCell through xib and change its frame somewhere in the code to be e.g. (120,120). You have to set its content view’s frame accordingly, otherwise image on its imageView (which is on its content view) will not be shown properly.

Sizing a Custom UITableViewCell and included UIImageView based on Image Size

I am trying to customize the UITableViewCell below for an iPhone app in a grouped table view. What I would like to do is have the image width take up the whole cell minus padding (280) and the height variable based on the image size.
Currently I am using SDWebImage to asynchronously download remote images. This may not be the correct thing to do in this case. I am also having trouble figuring out how to give the custom cell the image on initialization. The image URL is stored in self.beerPhoto in the DetailViewController.
I have searched for this a number of ways and have not found exactly what I am looking for. The closest was this: How to scale a UIImageView proportionally, but this method seems to require the cell to have the image at initialization, as I tried to make this code work but setting the image after initialization left a blank cell.
The current code includes constants I set to approximate an image in portrait orientation. In reality some of the images are portrait and some are landscape orientation.
Please let me know if there's anything additional you need to know.
Header for custom UITableViewCell:
#import <UIKit/UIKit.h>
#interface BeerDetailHead : UITableViewCell {
UILabel *beerName;
UIImageView *beerImage;
}
#property(nonatomic, retain)UILabel *beerName;
#property(nonatomic, retain)UIImageView *beerImage;
#end
Relevant portion of implementation for custom UITableViewCell
#import "BeerDetailHead.h"
#implementation BeerDetailHead
#synthesize beerName, beerImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
//beerName = [[UILabel alloc]init];
//beerName.textAlignment = UITextAlignmentLeft;
//beerName.font = [UIFont systemFontOfSize:14];
beerImage = [[UIImageView alloc]init];
//[self.contentView addSubview:beerName];
[self.contentView addSubview:beerImage];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,10, 280, 375);
beerImage.frame = frame;
}
DetailViewController's cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
NSLog(#"listData = %#", listData);
NSUInteger row = [indexPath row];
if ([self.sortedKeys objectAtIndex:[indexPath section]] == #"header"){
static NSString *headerTableIdentifier = #"HeaderTableIdentifier";
BeerDetailHead * headerCell = (BeerDetailHead*)[tableView
dequeueReusableCellWithIdentifier: headerTableIdentifier];
if(headerCell == nil) {
headerCell = [[[BeerDetailHead alloc] initWithFrame:CGRectZero reuseIdentifier:headerTableIdentifier] autorelease];
}
headerCell.beerName.text = [listData objectAtIndex:row];
[headerCell.beerImage setImageWithURL:[NSURL URLWithString:self.beerPhoto]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
//NSLog(#"frame = %#", headerCell.beerImage.frame);
return headerCell;
}
else{
//use standard UITableViewCell
}
}
Implement tableView:heightForRowAtIndexPath: delegate method and return calculated height for each row from this method.
After loading each image call reloadData on your tableView OR if you want to animate changes call:
[self.tableView beginUpdates];
[self.tableView endUpdates];
Also, you might want to combine several sequence height updates into one. I would use I little delay to perform this:
// triggerUpdates calls the above code
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(triggerUpdates) object:nil];
[self performSelector:#selector(triggerUpdates) withObject:nil afterDelay:0.1];

Objective C: Label Text (subclass of UIControl) not displayed in UITableview

I am trying to display a UILabel text (subclass of UIControl) in a cell of a tableview controller.
My code as follows:
In UIControl label .h file
#import <Foundation/Foundation.h>
#interface UIControlLabel : UIControl
{
UILabel *userNameLabel;
}
#property (nonatomic, retain) UILabel *userNameLabel;
#end
In UIControl.m file
#import "UIControlLabel.h"
#implementation UIControlLabel
#synthesize userNameLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(#"in init with frame method");
self.userNameLabel = [[UILabel alloc] init];
[self addSubview: userNameLabel];
}
return self;
}
#end
In tableviewcontroller .m file
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* PlaceholderCellIdentifier = #"PlaceholderCell";
int row = [indexPath row];
Answer *thisAnswer = [self.array objectAtIndex:row];
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier] autorelease];
UIControlLabel *control = [[UIControlLabel alloc]initWithFrame:CGRectMake(35, 10,100, 10)];
control.userNameLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:13.0];
control.tag = 2;
[cell.contentView addSubview:control];
}
UIControlLabel *thisControl = (UIControlLabel *)[cell.contentView viewWithTag:2];
thisControl.userNameLabel.text = [NSString stringWithFormat:#"%#",thisAnswer.userName];
return cell;
}
My issue is that the cell is not showing the label i set above. Is there something I am missing out here?
Seems like you're not setting a frame for your UILabel within your class.
Either call sizeToFit on UILabel, set the frame to match the whole size of your cell, use autosizeMask or implement -layoutSubviews in your UIControlLabel (then you might need to call [cell setNeedsLayout].