iOS - UILabel loading, but no text displaying - ios

I have implemented my own UITableViewCell and created a .xib for it. I have connected all the labels using a strong IBOutlet and initialized the UILabels in the awakeFromNib() method. However, whenever I run the iOS Simulator, I run into an issue where the UILabel is (null) in NSLog.
I am wondering if it has to do with how I am loading in the text for the UILabel. I have tried to create a shortened version of the project below that outlines the issue I'm running into.
I would also like to note that I can click on the actual rows, but that there is still no text displaying.
My code:
ToDoCell.h
#import <UIKit/UIKit.h>
#interface ToDoCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *minutesLeft;
#property (strong, nonatomic) IBOutlet UILabel *hoursLeft;
#property (strong, nonatomic) IBOutlet UILabel *daysLeft;
#property (strong, nonatomic) IBOutlet UILabel *taskLabel;
#end
ToDoCell.m
#import "ToDoCell.h"
#implementation ToDoCell
#end
ToDoViewController.m
#import "ToDoViewController.h"
#import "ToDoCell.h"
#interface ToDoViewController ()
#property NSMutableArray *toDoItems;
#end
#implementation ToDoViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];
}
- (void)loadInitialData {
NSString *item1 = #"Testing";
[self.toDoItems addObject:item1];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ToDoCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ToDoCell" forIndexPath:indexPath];
cell.taskLabel.text = #"Testing";
NSLog(#"Fudge Monkeys: %#", cell.taskLabel.text);
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
#end

Issue is you are creating new objects for labels but then you are not adding them to superview but calling [self addSubview:label] ssigning them to properties does not add them to super view.
But this is totally unnecessary you should not init them in awakeNib. , and one thing more I will say about your code now you don't need to use #synthesis anymore as well. Any particular reason you are making IBOutlets strong?
Update you need to register nib with tableView first add following lines in viewDidLoad
[tableView registerNib:[UINib nibWithNibName:#"ToDoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:#"ToDoCell"];
You can read more about this here

If the UILabel instances are connected in Interface Builder via IBOutlet, you must not initialize them explicitly.
Just delete the complete awakeFromNib() method

Add this in viewDidLoad
NSString *strName = NSStringFromClass([ToDoCell class]);
[self.toDoItems registerNib:[UINib nibWithNibName:strName bundle:nil] forCellReuseIdentifier:strName];
You are using xib file but not loading it by registering it for the tableView. This is required when you use separate xib file. If you do not register, then only class will load and xib won't. And your awakeFromNib won't be called.

First of all delete awakeFromNib and make sure that you gave Cell Identifier in cell nib file.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"ToDoCell";
ToDoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell)
cell = [[ToDoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: cellIdentifier];
cell.taskLabel.text = #"Testing";
return cell;
}
Don't forget to add following code for register nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.tableView registerNib:[UINib nibWithNibName:#"ToDoCellTableViewCell" bundle:nil] forCellReuseIdentifier:#"ToDoCell"];
}
Here is the sample code for your problem.
May this help to solve your problem.

You .xib why cell should be set through:
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
ToDoCell *cell = [tableView dequeueReusableCellWithIdentifier:[ToDoCell reuseIdentifier]];
if (!cell) {
cell = (ToDoCell *)
[[NSBundle mainBundle] loadNibNamed:#"ToDoCell" owner:self options:nil].firstObject;
}
cell.taskLabel.text = #"Testing";
NSLog(#"Fudge Monkeys: %#", cell.taskLabel.text);
return cell;
}

Related

[UITableViewCellContentView setText:]: unrecognized selector sent to instance

I have created a custom UITableViewCell with a XIB and connected the labels on it as outlets to the property. When I use that cell in my UITableViewController class to set the text on it, the app crashes during runtime with "[UITableViewCellContentView setText:]: unrecognized selector sent to instance" error. Below is my code:
Custom Table View cell .h and .m files:
#import <UIKit/UIKit.h>
#interface CustomTableViewCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UILabel *branchName;
#property (weak, nonatomic) IBOutlet UILabel *address;
#end
#implementation CustomTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
My UITableViewController code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *branchListCellId = #"branchList";
CustomTableViewCell *branchListCell = [tableView dequeueReusableCellWithIdentifier:branchListCellId];
if (!branchListCell) {
[tableView registerNib:[UINib nibWithNibName:#"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:branchListCellId];
branchListCell = [tableView dequeueReusableCellWithIdentifier:branchListCellId];
branchListCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
branchListCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
branchListCell.textLabel.numberOfLines = 0;
branchListCell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:17.0];
}
return branchListCell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(CustomTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//UILabel *branchName = (UILabel *)[cell.branchName viewWithTag:1];
cell.branchName.text = [self.branchList objectAtIndex:[indexPath row]];
}
Looking at the solution to other questions for the same crash here at SO, I even tries setting viewWithTag to something other than 0. I even tried recreating the outlets. Nothing helped.
What am I missing here?

Can't set Custom UITableViewCell property - iOS

First of all I want to apologize for my bad english.
I'm having trouble to set the properties of my custom UITableViewCell (HistoricoCell).
When I try to set a property of my cell I get: Signal SIGABRT error:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Dequeue the cell.
HistoricoCell *cell = (HistoricoCell *)[self.tblHistorico dequeueReusableCellWithIdentifier:#"CellIdentifier" forIndexPath:indexPath];
// Fetch Item
NSDictionary *item = [self.dbManager.arrColumnNames objectAtIndex:indexPath.row];
// Configure Table View Cell
[cell.lblCodigo setText:[NSString stringWithFormat:#"%#", item[#"codigo"]]];
[cell.btnFavoritar addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
I followed a lot of tutorials and questions on the web but I stil with my error.
Can someone help me?
My code:
HistoricoCell.h
#import <UIKit/UIKit.h>
#interface HistoricoCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UILabel *lblCodigo;
#property (weak, nonatomic) IBOutlet UIButton *btnFavoritar;
#end
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *tblHistorico;
SecondViewController.m
#import "SecondViewController.h"
#import "DBManager.h"
#import "HistoricoCell.h"
#interface SecondViewController ()
#property (nonatomic, strong) DBManager *dbManager;
#property (nonatomic, strong) NSArray *arrPeopleInfo;
-(void)loadData;
#end
#implementation SecondViewController
static NSString *CellIdentifier = #"CellIdentifier";
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Make self the delegate and datasource of the table view.
self.tblHistorico.delegate = self;
self.tblHistorico.dataSource = self;
// Initialize the dbManager property.
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:#"bernoullidb.sql"];
[self.tblHistorico registerClass:[HistoricoCell class] forCellReuseIdentifier:#"CellIdentifier"];
[self loadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadData{
// Form the query.
NSString *query = #"select * from tbHistorico";
// Get the results.
if (self.arrPeopleInfo != nil) {
self.arrPeopleInfo = nil;
}
self.arrPeopleInfo = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
// Reload the table view.
//[self.tblHistorico reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrPeopleInfo.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60.0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Dequeue the cell.
HistoricoCell *cell = (HistoricoCell *)[self.tblHistorico dequeueReusableCellWithIdentifier:#"CellIdentifier" forIndexPath:indexPath];
// Fetch Item
NSDictionary *item = [self.dbManager.arrColumnNames objectAtIndex:indexPath.row];
// Configure Table View Cell
[cell.lblCodigo setText:[NSString stringWithFormat:#"%#", item[#"codigo"]]];
[cell.btnFavoritar addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)didTapButton:(id)sender {
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#end
You should set cell indentifier "CellIdentifier" for your cell in File Inspector
Or register your nib file if you add cell with nib:
UINib *itemNib = [UINib nibWithNibName:#"yourCell" bundle:nil];
[self.tableView registerNib:itemNib forCellReuseIdentifier:#"yourCellReuseIndentifier"];
I think your problem is in your cell creation: you try to dequeue a cell if it exists (i.e. recycle a previously used cell). that is OK, but, especially when the TableView is displayed for the first time, no previously used cell for this table exists. So, you have to create one if the dequeueReusableCellWithIdentifier call return nil.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Dequeue the cell.
HistoricoCell *cell = (HistoricoCell *)[self.tblHistorico dequeueReusableCellWithIdentifier:#"HistoricoCellIdentifier" forIndexPath:indexPath];
if( cell == nil ) // no queuded cell to dequeue
{
// you have to create a fresh new one
cell = [HistoricoCell alloc] initWithStyle:<your cell style> reuseIdentifier:#"HistoricoCellIdentifier"];
}
// Fetch Item
NSDictionary *item = [self.dbManager.arrColumnNames objectAtIndex:indexPath.row];
// Configure Table View Cell
[cell.lblCodigo setText:[NSString stringWithFormat:#"%#", item[#"codigo"]]];
[cell.btnFavoritar addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}

Populate UITableView from NSMutableArray

Having an issue where the array values do not display in my tableview cells, but can be printed out correctly with NSLog. Thanks in advance for your help!
TableViewCell .h
#import <UIKit/UIKit.h>
#interface TableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UIImageView *image;
#property (strong, nonatomic) IBOutlet UILabel *label;
#end
TableViewController.h
#import <UIKit/UIKit.h>
#interface TableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
#property(nonatomic, strong) NSMutableArray *imagesArray;
#property(nonatomic, strong) NSMutableArray *namesArray;
#end
TableViewController.m
#import "TableViewController.h"
#import "TableViewCell.h"
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize primaryWeaponNames = _primaryWeaponNames;
- (void)viewDidLoad {
[super viewDidLoad];
[self setupArrays];
}
- (void)setupArrays {
_namesArray = [[NSMutableArray alloc] initWithObjects:
#"NAME1", #"NAME2", #"NAME3"
nil];
self.imagesArray = [[NSMutableArray alloc] initWithObjects:
#"IMG1", #"IMG2", #"IMG3"
nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (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.
return _namesArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableViewCell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.nameLabel.text = [NSString stringWithFormat:#"%#", [_namesArray objectAtIndex:indexPath.row]];
NSLog(#"%#", _namesArray[indexPath.row]);
cell.image.image = [self.imagesArray objectAtIndex:indexPath.row];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
When you make the cell in a xib file, you should register the nib in viewDidLoad. Since you didn't do that, the dequeue method will return nil, and you're just creating a default cell (in the if (cell == nil) clause) instead of your custom cell. The default cell doesn't have a nameLabel or image property, so the lines to set the values of those outlets won't do anything.
[self.tableView registerNib:[UINib nibWithNibName:#"Your nib name here" bundle:nil] forCellReuseIdentifier:#"TableViewCell];
In your TableViewController class, you need to include
self.tableView.delegate = self;
self.tableView.datasource = self;
in your viewDidLoad method. Or you can do this in interface builder by right click dragging the table view in your tableview controller to file's owner and setting delegate, then repeat for datasource

iOS7 CollectionViewCell not getting registered

I have a collection view with custom collection view cells. I am making lot of computations inside the cells and hence it takes sufficient amount of time for the cells to be rendered. Hence, I created my cells manually(i.e even before collection view is created) using the custom cells and inside the method of cellForItemAtIndexPath:, I am just returning my cells. The solution is working correctly for iOS6, but for iOS7, it is not working and I am getting the error of
*** Assertion failure in -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:],.
I have registered my cells and here is the brief amount of code.
MyMainVC.m
#implementation MyMainVC
- (void)viewDidLoad
{
NSArray *myArray = #[[MyCustomCell getCellAtRow:0], [MyCustomCell getCellAtRow:1], [MyCustomCell getCellAtRow:2]];
[self createCollectionView:myArray];
}
- (void)createCollectionView:(NSArray *)myArray
{
MyCollectionView *coll = [[[NSBundle mainBundle] loadNibNamed:#"MyCollectionView" owner:self options:nil] objectAtIndex:0];
[self.coll createCollectionViewWithEntries:myArray];
[self.view addSubView:coll];
}
#end
MyCollectionView.h
#interface MyCollectionView: UIView
- (void)createCollectionViewWithEntries:(NSArray *)myArray;
#end
MyCollectionView.m
#implementation MyCollectionView
- (void)createCollectionViewWithEntries:(NSArray *)myArray
{
self.myArray = myArray;
[self.collectionView registerNib:[UINib nibWithNibName:#"MyCustomCell" bundle:nil] forCellWithReuseIdentifier:#"MyCollectionView"];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.collectionView reloadData];
}
- (UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:#"MyCollectionView" forIndexPath:indexPath];
cell = [self.myArray objectAtIndex:indexPath.row];
return cell;
}
#end
MyCustomCell.h
#interface MyCustomCell: UICollectionViewCell
+ (MyCustomCell *)getCellAtRow:(NSInteger)row;
#end
MyCustomCell.m
#implementation MyCustomCell
+ (MyCustomCell *)getCellAtRow:(NSInteger)row
{
MyCustomCell *cell = [[[NSBundle mainBundle] loadNibNamed:#"MyCustomCell" owner:self options:nil] objectAtIndex:0];
[cell.tableView reloadData];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Not getting called in iOS7.
return cell;
}
#end
As you can see, there is tableView inside the collectionViewCell which I am reloading and then returning. Another thing is the method of cellForRowAtIndexPath is never getting called as well in iOS7. One probability which I believed was registering of nib should have been done before the cells are created. So I tweaked the MyMainVC.m file and created the variable of MyCollectionView *coll as instance variable and then created the cell. But that didn't work as well.
MyMainVC.m
#interface MyMainVC()
#property (strong, nonatomic) MyCollectionView *coll;
#end
#implementation MyMainVC
- (void)viewDidLoad
{
self.coll = [[[NSBundle mainBundle] loadNibNamed:#"MyCollectionView" owner:self options:nil] objectAtIndex:0];
[self.coll registerNib];
NSArray *myArray = #[[MyCustomCell getCellAtRow:0], [MyCustomCell getCellAtRow:1], [MyCustomCell getCellAtRow:2]];
[self createCollectionView:myArray];
}
- (void)createCollectionView:(NSArray *)myArray
{
[self.coll createCollectionViewWithEntries:myArray];
[self.view addSubView:self.coll];
}
#end
Inside MyCollectionView.m, I added one method as follows.
#implementation MyCollectionView
- (void)registerNib
{
[self.collectionView registerNib:[UINib nibWithNibName:#"MyCustomCell" bundle:nil] forCellWithReuseIdentifier:#"MyCollectionView"];
}
#end
I removed the registering in other method of createCollectionViewWithEntries:
Can anybody tell me what is going wrong? It is working fine for iOS6 but not for iOS7.
Thanks in advance for the help.

TableViewController cells not populating with data

Alright, I know I'm going to annoy someone here with my n00b-ness, so consider this a fair warning. I'm fresh-as-a-fish to Obj-C, and so what may be obvious to you most likely won't to me.
I've been following this tutorial on TableViewControllers, and I can't for the life of me get the cell titles to appear. I have cut and retailored every line of code on the site, and debugged a SIGABRT error, yet even now the data does not appear.
Here is the contents of the MasterViewController.h and /.m files, respectively:
The header file:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
#class DetailViewController;
#interface MasterViewController : UITableViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate, UITableViewDataSource>
#property (strong, nonatomic) DetailViewController *detailViewController;
// Create property "equations" as an instance of NSArray:
#property (strong, nonatomic) NSMutableArray *equations;
#property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#end
The implementation file:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
#end
#implementation MasterViewController
// Synthesize NSArray instance for equation storage:
#synthesize equations = _equations;
// Segue linking as per DetailViewController.h/.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *destViewController = segue.destinationViewController;
destViewController.equationName = [_equations objectAtIndex:indexPath.row];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.title = #"Equations";
if (!_equations)
{
_equations = [[NSMutableArray alloc] initWithObjects:
// Atomic structure equations:
#"Energy-Frequency Relation",
#"Energy-Frequency-Wavelength Relation",
#"Energy-Quantum Number Relation",
#"Momentum-Mass-Frequency",
#"Speed of Light Definition",
// Equilibrium equations:
#"Equilibrium Acid Constant",
#"Equilibrium Base Constant",
#"Water Equilibrium Constant",
#"pH Calculation",
#"pH-Acid Constant Relation",
#"pOH-Base Constant Relation",
#"pKa Derivation",
#"pKb Derivation",
#"pOH Calculation",
#"Gas-pressure Equlibrium",
// Gas/solution chemistry equations:
#"Ideal-Gas Law",
#"Partial-pressure equation",
#"Total pressure (3 partials)",
#"mol-Molarity Calculation",
#"Kelvin-Celsius Relation",
#"Fahrenheit-Celsius Relation",
#"Density Calculation",
#"Kinetic Energy per Molecule",
#"Kinetic Energy per Mol",
#"Molarity Equation",
#"Molality Equation",
#"Absorbance Equation",
#"Freezing Point Depression",
#"Boiling Point Elevation"
// Redox Equations:
#"Electrical current definition",
#"Equilibrium vs. Reduction Potential",
// Thermochemical relations:
#"Change in Free Energy",
#"Molar Heat Capacity",
#"Frequency to Rate Factor",
nil];
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return call from NSArray *equations as to the count of elements in the table view:
return [_equations count];
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
[lblName setText:[_equations objectAtIndex:[indexPath row]]];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
I spared y'all all 250 lines of code, cutting out only that seem to pertain to the view controller itself. Something tells me I'm simply leaving out a necessary line of code for connection, however my complete introductory status to the language as well as the lack of a debugger error doesn't trip me to it. Any ideas? Any help (nitpicking excluded) is more than appreciated and welcomed.
#"Cell"that could be a couple of things you can check here.
in your cellFoRowAtIndexPaht Method
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
//add this
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"] autorelease];
double check if your table data source and table delegate is connected correctly to your table view. i think when you create uitableviewcontroller from storyboard, it should connected for you automatically, but it won't harm to double check.
I was able to reproduce your issue as follows:
Your current tableView:cellForRowAtIndexPath: implementation requires that the cell have a UILabel subview with a tag of 100.
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
The label in the cell needs to be configured with this tag...
If you are using the "Basic" cell type in Interface Builder you have two options:
Option 1
You must select the title label and set it's tag to 100.
Option 2
Change the method to directly access the text label.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
[cell.textLabel setText:_equations[indexPath.row]];
return cell;
}
You can also use an approach similar to (if not identical to) Option 2 for custom cell types where you have provided your own label.

Resources