Custom table view cells show up blank (labels are nil) - ios

I'm using the same code that I use for other tables in my app, but I'm missing something here. None of my labels are being set as you can see in this image.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CommissionsCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CommissionsCell"];
CommissionInfo* tmpInfo = [g_commissionList objectAtIndex:[indexPath row]];
cell.backgroundColor=[UIColor colorWithWhite:0.95 alpha:1 ];
cell.lblDescription.text = tmpInfo.description;
cell.lblDate.text = tmpInfo.date;
cell.lblStatus.text = tmpInfo.status;
if([tmpInfo.imgThumbPath isEqualToString:#""]){
cell.lblInstructions.hidden=NO;
}else{
cell.lblInstructions.hidden=YES;
}
[cell.btnImg setImage:tmpInfo.img_thumb];
return cell;
}
I have all of my labels mapped in the CommissionsCell.h file any idea what's causing this?

Related

UITableViewCell custom label is not getting value

I'm currently creating a tableview with data from server. I have made it before, i copied over the code from the other files, but for some reason it's very strange. When i run the app, the tableview is empty and I found out that The cell.price.text is not updating, even though I hardcode it as #"123", cell.price.text is still showing null in NSLog.
I'm sure all these three method are called, because I put nslog in each of them
//TableView Setting
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(#"Countdata %i",countdata);
return countdata;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ShopTableViewCell";
ShopTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ShopTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
NSLog(#"hi");
}
// Configure the cell...
cell.price.text = [self.gprice objectAtIndex:[indexPath row]];
NSLog(#"Good,%#",[self.gprice objectAtIndex:[indexPath row]]);
NSLog(#"text,%#",cell.price.text);
return cell;
}

IOS: UITableView Jerks When Scrolling Up

I am having this weird issue where my UITableView starts jerking or stuttering when scrolling up, but as soon as I scroll up all the way, it is fine. I am using this table view to hold a chat conversation. I am using a custom cell, and it is only populating text on two labels.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MessagesInfo" forIndexPath:indexPath];
//
// Configure the cell...
WinMessagesInfoCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"MessagesInfo" forIndexPath:indexPath];
if (cell == nil) {
cell = [[WinMessagesInfoCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"MessagesInfo"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *userId = [defaults valueForKey:#"loggedInUserId"];
NSLog(#"Line 791 WinMessageViewController");
if ([self.sender_id objectAtIndex:indexPath.row])
{
if ([[self.sender_id objectAtIndex:indexPath.row] isEqual:userId]){
cell.friendName.textColor = [UIColor blueColor];
cell.friendName.text = #"Me";
}
else
{
cell.friendName.textColor = [UIColor greenColor];
cell.friendName.text = [self.from objectAtIndex:indexPath.row];
}
cell.friendMessage.text = [self.message objectAtIndex:indexPath.row];
}
return cell;
}
Update:
This issue appears to be the height of my cells, if I take out the dynamic cell growth, the issue goes away, but I need them to grow dynamically. I am currently using the following:
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
//minimum size of your cell, it should be single line of label if you are not clear min. then return UITableViewAutomaticDimension;
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
The estimates must be bad. Any advice to get a better estimate? There are two labels in the cell and only one of the labels will change in size.

After searching filtering in tableview, why it shows blank cell?

Now I have a dynamic cell to show lists. And Using Search Bar and Search Display Controller. Why it shows blank on simulator.
Before filtering,the simulator shows all cells and disclosure could link to another table view. After filtering, it should show some of cells. But it is blank. And the disclosure is not worked as well.
Codes for cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"MovieCell";
MovieCell *cell = (MovieCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Movie *movie = nil;
if (cell == nil) {
cell = [[MovieCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
movie= [filteredMovieArray objectAtIndex:[indexPath row]];
} else {
movieArray = self.movies;
movie = [movieArray objectAtIndex:[indexPath row]];
}
cell.nameLabel.text = movie.movieName;
cell.placeLabel.text = movie.place;
cell.categoryLabel.text = movie.category;
cell.isFavLabel.text = movie.isFavourite ? #"Favourite" : #"Not Favourite";
[cell.starRating setRating:movie.rating];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
NSLog(#"description = %#",[cell description]);
return cell;
}
I made it. I think this is a good answer for it: Search Bar in UITableView doesn't display text in Cell label.
What's more, I also add this code section to fit the cell height:
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
tableView.rowHeight = 87;
}
This number is the row height of my cell.

UITableView textlabel frame not showing proper

I developed iPhone app in which i have UITableView.
UITableViewCell textlabel frame is not proper according to text,
when i write this code, UITableView textlabel is not proper.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CategCellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CategCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CategCellIdentifier];
}
cell.textLabel.backgroundColor=[UIColor redColor];
cell.textLabel.font= [UIFont systemFontOfSize:12.0];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = [tempArr objectAtIndex:indexPath.row];
return cell;
}
when i pass my array to UITableView it shows like this:
Whats the problem ? where i am doing mistake, please help
I am not sure what text your array contains. But, I have created an example of my own. Here is the code :
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CategCellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CategCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CategCellIdentifier];
}
cell.textLabel.backgroundColor = [UIColor redColor];
cell.textLabel.font= [UIFont systemFontOfSize:20.0];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = #"Brand";
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.backgroundColor = [UIColor redColor];
}
#end
Here is the output :
I have used your code. Only difference I made is, I am applying red colour to text label in willDisplayCell: method of UITableViewDelegate.
Coming to the margins that appears on both sides of the tableview are as per Apple's UI guidelines.
Let me know if you need my code.
Try to set Size to fit with content After setting Text.
[cell.textLabel sizeToFit];
Thanks.
Check table row height property in size inspector, may be some thing wrong with it
[tableView setRowHeight: 100.00];
or you can use delegate to set row height
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Add row in UITableView in prototype cell mode (that's not what my expect)

I have UITableView with prototype cell.I have a label in cells with various values(text value).
when add a new row, some of labels in new rows created with previous cell values not default values:
What can i do?
Is my question clear?
This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
gamers = [[NSMutableArray alloc] initWithObjects:#"Player1",#"Player2", nil];
}
- (IBAction)btnAddRow:(id)sender {
[gamers addObject:#"new player"];
[_tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tableIdentifier = #"gamerCell";
nTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if (cell == nil) {
cell = [[nTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
}
cell.lblTitle.text = [gamers objectAtIndex:indexPath.row];
return cell;
}
Please find the updated project in the link
UITableView-dynamic-row-buttons
Hope this helps.
Where do you update the score? if you are not doing, make, according to your logic, and then set this value in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tableIdentifier = #"gamerCell";
nTableViewCell *cell = (nTableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if (cell == nil) {
cell = [[nTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
}
cell.lblTitle.text = [gamers objectAtIndex:indexPath.row];
cell.lblScore.text = [NSString stringWithFormat:#"%i", (int)scoreProperty];
return cell;
}

Resources