UITableViewCell does not appear in my table - objective-c

I have an UITableVIew. Now I made my own UITableViewCell. But if my table appears nothing is shown. However the cells are still selectable and open the DetailView. Which command have I forgotten?
//Customize the appearance of table view cells.
-(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"MainTableCell";
MainTableCell *cell = (MainTableCell*)[tableView dequeueReusableCellWithIdentifier:Cel lIdentifier];
if (cell == nil) {
cell = [[[MainTableCell alloc] initWithStyle:UITableViewCellStyleDef ault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
VerwaltungInformation *selectedFormel = [listOfFormularies objectAtIndex:indexPath.row];
cell.FormelNameLabel.text = selectedFormel.nameFormel;
return cell;
}
Do I have to add special things? If somebody needs more code - please tell me.
Here is my MainTableCell.h:
import <UIKit/UIKit.h>
#interface MainTableCell : UITableViewCell {
UILabel *FormelNameLabel;
UILabel *ErklaerungVerfuegbarLabel;
UILabel *BeispielVerfuegbarLabel;
UILabel *RechnerVerfuegbarLabel;
}
#property (nonatomic, retain) IBOutlet UILabel *FormelNameLabel;
#property (nonatomic, retain) IBOutlet UILabel *ErklaerungVerfuegbarLabel;
#property (nonatomic, retain) IBOutlet UILabel *BeispielVerfuegbarLabel;
#property (nonatomic, retain) IBOutlet UILabel *RechnerVerfuegbarLabel;`
#end
And here is my MainTableCell.m:
#import "MainTableCell.h"
#implementation MainTableCell
#synthesize FormelNameLabel;`
#synthesize ErklaerungVerfuegbarLabel;
#synthesize BeispielVerfuegbarLabel;
#synthesize RechnerVerfuegbarLabel;`
- (void)dealloc {
[FormelNameLabel release];
[ErklaerungVerfuegbarLabel release];
[BeispielVerfuegbarLabel release];
[RechnerVerfuegbarLabel release];
[super dealloc];
}
#end

you have commented this line
cell. VerwaltungInformation *selectedFormel = [listOfFormularies objectAtIndex:indexPath.row];
and also check wthr
selectedFormel.nameFormel
contains any value.

ok, I'll try to answer.
1.try to NSLog this value selectedFormel.nameFormel before setting it to the label.text.
NSLog(#"selectedFormel.nameFormel:%#", selectedFormel.nameFormel);
2.Have you configured your cell properly? are you sure that for example FormelNameLabel's frame is not zero?
NSLog(#"cellFrame:%#", NSStringFromCGRect(cell.frame));
Are you sure that you have added a label to the cell as subview?
If all these things are done and it still shows nothing provide a code from your cell!

Related

UILabel in detail view is not being populated

I have a UITableView populated with an array of data gathered from an SQLite database. When a cell is selected a detail view is loaded relevant to that cell. The title on the navigation controller changes ok but a UILabel on the detail view does not get populated.
Relevant tableViewController code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
ExhibitorDetailViewController *exhibitorDetailViewControllerInstance = [[ExhibitorDetailViewController alloc] init];
exhibitorDetailViewControllerInstance.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
exhibitorDetailViewControllerInstance.exhibitorDetailModal = [arrayOfExhibitors objectAtIndex:indexPath.row];
// Have tried setting the text before the detail view is loaded wiht the line below
exhibitorDetailViewControllerInstance.LabelExhibitorDescription.text = arrayOfExhibitors.description;
[self.navigationController pushViewController:exhibitorDetailViewControllerInstance animated:YES];
}
The viewDidLoad event of the detail view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = _theTitle; //This sets the title ok
NSLog(#"0 - %#", _exhibitorDetailModal.description); //This property is what I want to fill the UILabel with
self.LabelExhibitorDescription.text = _exhibitorDetailModal.description; // This does nothing
self.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.8 blue:0.8 alpha:2.0f]; // If I don't set the background colour here it loads up black (despite being set in the storyboard)
NSLog(#"label text = %#", self.LabelExhibitorDescription.text); // This shows the text box being null despite having its text property set above
}
Detail view header file:
#interface ExhibitorDetailViewController : UIViewController
{
}
#property (nonatomic, retain) NSString *theTitle;
#property (strong, nonatomic) IBOutlet UILabel *nameLabel;
#property (strong, nonatomic) IBOutlet UILabel *categoryLabel;
#property (strong, nonatomic) IBOutlet UILabel *descriptionLabel;
#property (strong ,nonatomic) NSArray *exhibitorDetailModal;
#property (strong, nonatomic) IBOutlet UILabel *LabelExhibitorDescription;
#end
Why isn't the UILabel text being populated?
Thanks.
Edit:
I have logged the 'outgoing' description of the array - [arrayOfExhibitors objectAtIndex:indexPath.row] and this shows the correct data as expected which is the same as the _exhibitorDetailModal.description which is shown in the detail view.
To get this working in the end I rewrote the entire code and tidied it up along the way.
To get the UILabel displaying properly I first passed the description property of the exhibitorDetailModal object to an NSString.
_stringExhibitorDescription = _exhibitorDetailModal.description;
I then initialised the UILabel.
self.labelExhibitorName = [[UILabel alloc]init];
Then set the text of the UILabel to be that of the NSString above
[_labelExhibitorName setText:_stringExhibitorName];
Then added the UILabel as a subView of UIView.
[self.view addSubview:_labelExhibitorDescription];

An IBOutlet is not initiated

I'm trying to make a tableview with customized cells.
I've created 2 files .m and .h that refer to my class CustomCell.
Here is the code :
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell
{
IBOutlet UIImageView *miniLogo;
IBOutlet UILabel *cellText;
IBOutlet UIButton *deleteButton;
}
#property (strong, nonatomic) IBOutlet UIImageView *miniLogo;
#property (strong, nonatomic) IBOutlet UILabel *cellText;
#property (strong, nonatomic) IBOutlet UIButton *deleteButton;
#end
-------------------------------------------------------------
#import "CustomCell.h"
#implementation CustomCell
#synthesize miniLogo,cellText, deleteButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
}
/*
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}*/
#end
With a .xib file, i've designed my cell, and connected the IBOutlets and set the Identifier for the cell.
In the table with my customized cells, I call the cells in the method tableView:cellForRowAtOndexPath: like this :
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellsIdentifier ];
if (cell == nil){
UIViewController *tempVC = [[UIViewController alloc] initWithNibName:#"CustomCell" bundle:nil];
cell = (CustomCell *)tempVC.view;
}
When I launch my app, the labels display the texts set, and the image views show the right images. But the buttons don't appear. In fact, when setting break points, I seen that address for my buttons are always 0x00000000 (means that my buttons aren't initiated).
Can someone help me to solve this problem please.
I've found the problem.
In he viewDidLoad I was doing :
UINib *cellNib = [UINib nibWithNibName:#"myCells" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:CellsIdentifier];
But because I have changed my .xib name, I wasn't loading the right interface.
What is strange is that I don't have any nib named "myCells".
Maybe I should have perform a "clean" on my project...

UITextField inside UITableViewCell won't become first responder

I use a UITableViewController to display the details of KoreanFood. The first cell is a custom UITableViewCell (OverviewCell) with an Image and two UITextFields, which I created and layout in Storyboard (AutoLayout).
I subclassed UITableviewCell like this:
// OverviewCell.h
#interface OverviewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UITextField *englishTitleTF;
#property (strong, nonatomic) IBOutlet UITextField *koreanTitleTF;
#property (strong, nonatomic) IBOutlet UIImageView *myImageView;
#property (strong, nonatomic) UIImage *thumbnail;
My textfields in Storyboard are set to enabled/UserInteractionenabled and the delegate is my TVC. When I create the cells I also do this in code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == GENERAL_SECTION) {
static NSString *overviewCellID = #"overviewCell";
OverviewCell *overviewCell = [tableView dequeueReusableCellWithIdentifier:overviewCellID forIndexPath:indexPath];
overviewCell.englishTitleTF.text = self.generalInfo.titleEnglish;
overviewCell.koreanTitleTF.text = self.generalInfo.titleKorean;
overviewCell.englishTitleTF.enabled = YES;
overviewCell.koreanTitleTF.enabled = NO;
//BOOL test = [overviewCell.englishTitleTF becomeFirstResponder];
overviewCell.koreanTitleTF.delegate = self;
overviewCell.englishTitleTF.delegate = self;
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.generalInfo.thumbnail];
overviewCell.myImageView = imageView;
overviewCell.myImageView.frame = CGRectMake(25, 25, 95, 95);
[overviewCell addSubview:overviewCell.myImageView];
return overviewCell;
}
The comment with the BOOL is NO, and I just don't know why... As I set the text and it's displayed correctly, I know the Outlets are set and the Cell isn't nil (I checked that).
Why does this not become first responder?
I also tried some suggestions inside the OverviewCell subclass like the hit test or implementing the setSelected: / setEditing: methods. But a becomeFirstResponder to the textField here doesn't change anything as well.
A view can't become first responder until it's been added to the responder chain, which happens automatically when the view gets added as a subview of a view that's in a window in the application object's windows list. In other words, your cell hasn't been added to the table view yet, so it's not connected to anything, and hence can't become first responder.
Try sending becomeFirstResponder from a method that gets called after the table view has finished loading its cells. And of course, don't do this:
overviewCell.koreanTitleTF.enabled = NO;

custom uitableviewcell will not display label texts

And the value of the labels are null as well.
I'm not really sure what's going on.
These are my classes/codes
#interface CustomEventCell : UITableViewCell{
}
#property (nonatomic, weak) IBOutlet UILabel *participant1label;
#property (nonatomic, weak) IBOutlet UILabel *participant2label;
#property (nonatomic, weak) IBOutlet UILabel *status;
#end
Event model is
#interface Event : NSObject{
}
#property NSNumber *matchId;
#property NSString *participant1, *participant2,
-(id)init;
#end
this is the tableview that fills up the cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"EventCell";
CustomEventCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[CustomEventCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// events is a NSMutableArray with Event instances
Event *event = [events objectAtIndex:indexPath.row];
cell.participant1label.text = event.participant1;
return cell;
}
Here's my setup
I must be missing something as I have another uitableview and it populatees the custom without problems. I compared them and they're identical. I even tried going back to the regular label and it would fill that up but not this custom one.
EDIT:
Modified the wrong copied code.
I wrote a simple little test app attempting to replicate what you want to see working. I have made it available here using Storyboards. If you cannot figure it out from this, then perhaps you can take the test app and modify it so that it replicates the bad behavior you are seeing.
My best guess as to what might be going on is that when you initialize your cell, it is not connected to a view in a xib.
Try setting a breakpoint at:
cell.participant1label.text = event.participant1;
and verify that cell.participant1label is not nil by doing:
NSLog( #"cell.participant1label: %#", cell.participant1label );
I had a small bug in which none of my custom labels were showing up and cell.participant1label was nil. The cause was that I had not set the Identifier for the custom table view cell to 'EventCell'. So, I might suggest rechecking that and making sure the identifier really does match between your code and the XIB.

How to reload UItableView that is inside UiViewController

I have a UITableView inside UiViewController.
In the same screen, I also have two buttons: Show All vs Show Top 5.
Now based on a selection all/top 5, I have to update table data.
I cant use [tableView reloadData] as I am not using UITableViewController.
This is the first time I am working on an iphone app. So any help is appreciated.
(I used this tutorial to get started http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/)
Thanks.
Here is a snippet of my code:
.h file
#interface DataViewController : UIViewController {
NSString *showType;
}
#property (nonatomic, retain) NSString *showType;
-(IBAction) showTop: (id) sender;
-(IBAction) showAll: (id) sender;
#end
.m file
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = #"customCell";
DataCustomCell *cell = (DataCustomCell *) [tableView dequeueReusableCellWithIdentifier:cellID];
if([showType isEqualToString:#"all"])
{
// use this data..
}
else
{
// use some other data..
}
// ....
}
-(IBAction) showNearby: (id) sender
{
self.showType=#"top";
// reload table some way
}
-(IBAction) showAll: (id) sender
{
self.showType=#"all";
//reload table some way
}
Create a UITableView IBOutlet like this
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
in your UIViewController's interface file. Then have that connect to the UITableView in Interface Builder. After synthesizing it in your implementation file, you should be able to access it like this
[self.myTableView reloadData];
Also, since you retained it, you will have to release myTableView in the dealloc method.