Change image on click in custom table cell made from nib - ios

I have a table with custom cells that are made from a nib file. When a user clicks a cell it expands in height , thus simulating a dropdown. In the custom cell there is an imageView that has a dropDown image when the cell is not clicked. However when the cell is clicked it should change the image to a collapse image or arrow up image to show that the cell is open.
I am having a problem changing the image when the cell expands from arrow down to arrow up and vice versa. I would like assistance achieving this.
Here is my code :
ViewController.h
#interface ViewController : UIViewController <UITableViewDelegate,
UITableViewDataSource>
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property(nonatomic, strong) NSArray *items;
#property (nonatomic, assign) BOOL expandFlag;
#property (nonatomic, assign) NSIndexPath* selectedIndex;
ViewController.m
- (NSArray *) items
{
if (!_items) {
_items = [NSArray new];
}
return _items;
}
- (void)viewDidLoad {
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:#"CustomTableViewCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:#"cell"];
_items = #[
#{#"title":#"Simpson", #"short":#"Homer", #"long":#"Mr jhvjm,b;k t tyfy rctrc rtcf rvty rthvgh bb r5ertvyg hg r5 tyhg 6ruygj 8rutyj r6yiugg tygdtjhgfdt hg tvt gthgfgni7yjftgjhb ftgfh b yjh gtfjfyhh j jj j", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."},
#{#"title":#"Simpson", #"short":#"Marge", #"long":#"Mrs bjyvhm uikn o utv jb k", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."},
#{#"title":#"Simpson", #"short":#"Bart", #"long":#"Mr vubj cbjknuy iubyuvjh biubkj ", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."},
#{#"title":#"Simpson", #"short":#"Lisa", #"long":#"Miss jbjvjbbiuvu yuvhj uby ", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."},
#{#"title":#"Simpson", #"short":#"Maggie", #"long":#"Miss iubniyujh k iuuh ", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."},
#{#"title":#"Flanders", #"short":#"Ned", #"long":#"Mr hbuyvj iybkj nui uhc n", #"image":#"There are many ways to create expandable cells in the table view. Few of them you can easily find on this blog or somewhere in Google. One of that is the official Apple “Date cell” demo code. However, most of that describing the little hard way by using operations directly on constraints."}
];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) didExpandCell{
_expandFlag = !_expandFlag;
[self.tableView reloadRowsAtIndexPaths:#[_selectedIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.items.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
NSDictionary *item = _items[indexPath.row];
cell.titleImage.text = [item objectForKey:#"title"];
cell.longLabel.text = [item objectForKey:#"long"];
cell.shortLabel.text = [item objectForKey:#"image"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_selectedIndex = indexPath;
[self didExpandCell];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (_expandFlag && _selectedIndex == indexPath) {
return 400;
}
return 200;
}
CustomeTableViewcell.h
#interface CustomTableViewCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UIImageView *thumbImage;
#property (weak, nonatomic) IBOutlet UILabel *titleImage;
#property (weak, nonatomic) IBOutlet UILabel *shortLabel;
#property (weak, nonatomic) IBOutlet UILabel *longLabel;
#property (weak, nonatomic) IBOutlet UIImageView *dropDownImage;
CustomerTableViewCell.m
- (void)awakeFromNib {
[super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}

You should check and change dropDownImage in cellForRowAtIndexPath method. Something likes the code below
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
NSDictionary *item = _items[indexPath.row];
cell.titleImage.text = [item objectForKey:#"title"];
cell.longLabel.text = [item objectForKey:#"long"];
cell.shortLabel.text = [item objectForKey:#"image"];
NSString *dropDownImageName = [indexPath isEqual:_selectedIndex] && _expandFlag ? #"ARROW_DOWN" : #"ARROW_UP";
cell.dropDownImage.image = [UIImage imageNamed:dropDownImageName];
return cell;
}
Change ARROW_UP and ARROW_DOWN with your image names.

Related

XCode TableViewController to detail in Objective-C

I have a TabBarController with 4 tabs, 3 of which are table views. I am trying to put a detail for every table view cell, and I don't think storyboard is efficient since I have over 50 detail pages. I'm very new to all of this, and I've tried to find out how to link a detail to every tab for a couple hours. My table views start with the Second View Controller.
Here is SecondViewController.m:
#import "SecondViewController.h"
#implementation SecondViewController
{
NSArray *tableData;
}
#synthesize tableData;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
tableData = [NSArray arrayWithObjects:#"Carter", #"Greene", #"Hancock", #"Hawkins", #"Johnson", #"Sullivan", #"Unicoi", #"Washington", nil];
[super viewDidLoad];
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
#end
Here is SecondViewController.h:
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController <UITableViewDelegate,
UITableViewDataSource>
#property(nonatomic, retain) NSArray *tableData;
#end
If this helps, here is my storyboard.
If anyone can help me individually add details to each table view cell in the most painless way possible, I would appreciate it. Thanks!
If using storyboards, the process is fairly simple.
First, I'd suggest dragging a prototype "table view cell" on to your table views. You can then control-drag from that prototype cell to your destination scene to add a segue between the cell and the next scene:
Make sure to select that prototype cell and set its storyboard identifier (I used "Cell"). You will need to reference that storyboard identifier, as shown in my code sample below. I also configured appearance related things (like the disclosure indicator) right in that cell prototype in IB so I don't have to worry about doing that in code and I can see what the UI will look like right in IB.
Now you can go to the table view controller and (a) simplify cellForRowAtIndexPath (because you don't need that logic about if (cell == nil) ... when using cell prototypes); but also implement a prepareForSegue to pass the data to the destination scene:
// SecondViewController.m
#import "SecondViewController.h"
#import "DetailsViewController.h"
#interface SecondViewController ()
#property (nonatomic, strong) NSArray *tableData;
#end
#implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableData = #[#"Carter", #"Greene", #"Hancock", #"Hawkins", #"Johnson", #"Sullivan", #"Unicoi", #"Washington"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.destinationViewController isKindOfClass:[DetailsViewController class]]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *name = self.tableData[indexPath.row];
[(DetailsViewController *)segue.destinationViewController setName:name];
}
}
- (IBAction)unwindToTableView:(UIStoryboardSegue *)segue {
// this is intentionally blank; but needed if we want to unwind back here
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.tableData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = self.tableData[indexPath.row];
return cell;
}
#end
Obviously, this assumes that you created a DetailsViewController and specified it as the destination scene's base class, and then create properties for any values you want to pass to this destination scene:
// DetailsViewController.h
#import <UIKit/UIKit.h>
#interface DetailsViewController : UIViewController
#property (nonatomic, copy) NSString *name;
#end
And this destination scene would then take the name value passed to it and fill in the UILabel:
// DetailsViewController.m
#import "DetailsViewController.h"
#interface DetailsViewController ()
#property (weak, nonatomic) IBOutlet UILabel *nameLabel;
#end
#implementation DetailsViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.nameLabel.text = self.name;
}
#end
Frankly, this process will undoubtedly be described more clearly in any UITableView tutorial includes a discussion of "cell prototypes" (your code sample suggests you were using an older tutorial that predates cell prototypes).
I think the relationship between the code and the storyboard is as following:
Code implement the function of the application.
Storyboard contains many scenes, these scenes implement the User interface, including data presentation, data input, data output.
Code read data from these scenes and output the result to the scenes.
Code is internal logic function entities and the storyboard the the User Interface presentation.

Table view scrolling all the way down not working

I got 3 labels on my view displaying some stuff, a table view below (beginning at screen halfway down) and
a data retrieval method where I fill up an NSArray for the table view.
Everything works, the problem now is if there are more than a few elements in the array for the table view (more than the screen can display at once) I'm not able to scroll down to the bottom, it's always autoscrolling up again, as if the table view was empty space there (which it is not, I checked of course).
It worked on the previous screen the way I did it, I think the iOS doesn't notice the labels or something similar - it thinks the table view has the whole screen for itself. I tried resizing the table view in the xib to let it end just before the screen ends but the table view occupies all screen beginning from where it started. I also tried to
initWithFrame:CGRectMake...
But this did not work as well. Any ideas whats going on here? I'd be really glad about some help, thanks guys!
EDIT:
.h file
#interface ZProjekt : UIViewController <RetailHeaderTabSource, MFMailComposeViewControllerDelegate , UITableViewDelegate, UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDataSource>
{
NSString *messageBody;
NSString *subjectBody;
NSMutableArray *fieldsInTable;
int fieldscounter;
}
#property (strong, nonatomic) IBOutlet UILabel *tableNamed;
#property (strong, nonatomic) IBOutlet UILabel *objectsInTable;
#property (strong, nonatomic) NSArray *DetailModal;
#property (strong, nonatomic) IBOutlet UILabel *mboSyncGroup;
#property (strong, nonatomic) IBOutlet UITableView *tableView;
#end
here is the code of the tableview .m file
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return fieldscounter;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = fieldsInTable[indexPath.row];
[Constants updateLabelValues:cell.textLabel withKey:k_IPhone_DetailCell_HeaderLabel];
return cell;
}
Try this one :
[tableView setContentOffset:CGPointMake(tableView.frame.size.width, tableView.frame.size.height) animated:NO];
or
on the TableViewController->Table View check the clip Subviews n Autoresize Subviews.
Also,
make sure the total rows are the same with the total contents in the tableView which is 3
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}
Problem Found ! The problem is, the tableview doesn't know which table you are scrolling either the last one or the previous one. You need to re-assign the value to the NSMutableArray. You need to store the content of the array in the table1 into array or dictionary and you need to reassign in the CellForRowIndexPath. I had the same problem like this.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView != table2.tblView) {
fieldsInTable = table1.fieldsInTable;
}
else
{
fieldsInTable = table2.fieldsInTable;
}
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = fieldsInTable[indexPath.row];
[Constants updateLabelValues:cell.textLabel withKey:k_IPhone_DetailCell_HeaderLabel];
return cell;
}

UITableView cells are not displaying text

I just finished a simple 5 minute UITableView tutorial. I even imported the tutorial's source code files into my own current xcode project, and I still cannot get this to work. I'm not sure if I'm doing something wrong, or if it's because the tutorial was created using a different version of xcode or what.
Anyways, I created a new objective-c file called "TVTViewController" which is a subclass of UIViewController. I then dragged a UIViewController onto the storyboard and set it's custom class in the attributes inspector to "TVTViewController".
Next, I dragged a UITableView object onto the UIViewController that I just dragged onto the storyboard.
I set the UITableView's "Content" setting to "Dynamic" and then set it's "Prototype Cells" setting to "1".
I then selected the prototype cell on the storyboard, and changed it's "Style" setting to "Subtitle", and changed it's "Identifier" setting to "SettingsCell".
Finally, here is my header file code:
#import <UIKit/UIKit.h>
#interface TVTViewController : UIViewController <UITableViewDataSource>
#end
And here is my main file's code:
#import "TVTViewController.h"
#interface TVTViewController ()
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property (strong, nonatomic) NSArray *tweetsArray;
#end
#implementation TVTViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//1
self.tableView.dataSource = self;
//2
self.tweetsArray = [[NSArray alloc] initWithObjects:
#"Always put your fears behind you and your dreams in front of you.",
#"A relationship with no trust is like a cell phone with no service, all you can do is play games.",
#"People should stop talking about their problem and start thinking about the solution.",
#"Dear Chuck Norris, Screw you. I can grill burgers under water. Sincerely, Spongebob Squarepants.",
#"My arms will always be open for you, they will never close, not unless you're in them.",
nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//3
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tweetsArray count];
}
//4
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//5
static NSString *cellIdentifier = #"SettingsCell";
//6
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSString *tweet = [self.tweetsArray objectAtIndex:indexPath.row];
//7
[cell.textLabel setText:tweet];
[cell.detailTextLabel setText:#"via Codigator"];
return cell;
}
#end
When I run my app on my iPhone, it shows the table view, but it is empty. None of the text is displayed in the table view's cells at all. This is pretty much copy and pasted from the tutorial's source code, and when I run the tutorial's source code app on my iPhone it displays the text in the cells just fine.
I don't understand why it is not working for me once I add the same code to my own app.
Thanks for the help.
EDIT:
I just figured it out on my own. The tutorial author neglected to tell you to connect the IBOutlet called "tableView" to the UITableView object. I just connected them and everything is displaying fine now. I would answer my own question but stackoverflow won't let me for another 8 hours.
A possible work around:
a) Check that the cell were actually created or not:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if( !cell )
{
cell = [[UITableViewCell alloc] init];
}
b) Set its delegate and datasource
Check out other ways to dequeue table view cells
Add UITableViewDelegate, like
#interface TVTViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
with
self.tableView.delegate = self;
And create cell as
if(cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

Data is disappearing from UITableView

I am building an iOS app with a custom tab bar at the top. When i click on the home icon, I want it to show a tableview directly below the tab bar. Currently my code does just that, however the data doesnt show correctly. If I limit my Cells to 4 or less (in the numberFoRowsInSection), the data will show, if i have like say 15 cells, the data shows for a split second and then it disappears. I have been looking at tutorials all over the place and everything seems to be correct, the data will show correctly in a stand alone view(like i created a similar to a singleview application in the story board and made that the initial view). I dont know where i am wrong. Below is my code in implementation file of the tableviewContoller class:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 4;//this works... but change to 15 it doesnt work
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PrayerCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CustomCell"];
if (cell == nil) {
NSLog(#"cell is Nil"); //never hits this
cell = [[PrayerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"CustomCell"];
}
//the data showing is the correct data that i want to see
cell.dName.text = [[news objectAtIndex:indexPath.row] objectForKey:#"displayname"];
cell.priority.text = [[news objectAtIndex:indexPath.row]objectForKey:#"priority"];
cell.dateTime.text = [[news objectAtIndex:indexPath.row] objectForKey:#"datetime"];
cell.numPraying.text = #"2 praying";
cell.requestPreview.text = [[news objectAtIndex:indexPath.row] objectForKey:#"request"];
NSLog(#"created cell") //verify cell was made
return cell;
}
Here is my PrayerCell.H file
#interface PrayerCell : UITableViewCell
#property (weak, nonatomic)IBOutlet UILabel *requestPreview;
#property (weak, nonatomic)IBOutlet UILabel *dName;
#property (weak, nonatomic)IBOutlet UILabel *dateTime;
#property (weak, nonatomic)IBOutlet UILabel *numPraying;
#property (weak, nonatomic)IBOutlet UILabel *priority;
#end
I made no Changes to the prayerCell.M file
if you need me to post any other code blocks/screenshots please let me know.
The cell should not be an ivar, it should be a local variable. You also need to dequeue the cell in your tableView:cellForRowAtIndexPath: method:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:#"CustomCell"];

Not possible to add row to a UITableView

I'm a newbie programming iOS and I've a problem adding a new cell to a UITableView object. I'm using an storyboard and one of the scenes is a UIViewController that has several subviews: textfields, a tableview, etc. I intend to add rows to this tableView from a detail scene.
I'm able to initially add rows to the table, but I'm not able to add a row afterwards. When I press a button to add the row I call the method '[self.stepsListTableView reloadData];' which produces a call to the method '- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section' and it returns a correct value, including the new array element. But method '- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath' is not called to update the table.
I do not understand what I'm doing wrong.
Details of my source code:
WorkoutDetailsViewController.h
(…)
#interface WorkoutDetailsViewController : UIViewController <StepDetailsViewControllerDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, weak) id <WorkoutDetailsViewControllerDelegate> delegate;
#property (nonatomic, strong) Workout *workout;
(…)
#property (nonatomic, retain) IBOutlet UITableView *stepsListTableView;
(…)
WorkoutDetailsViewController.m
(…)
#synthesize stepsListTableView;
(…)
- (void)viewDidLoad
{
[super viewDidLoad];
addButton.enabled = FALSE;
workoutNameField.delegate = self;
if (self.workout == nil) {
self.workout = [[Workout alloc] init];
self.stepsListTableView = [[UITableView alloc] init];
}
self.stepsListTableView.delegate = self;
self.stepsListTableView.dataSource = self;
}
(…)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return [self.workout.stepsList count];
NSInteger counter = 0;
counter = [self.workout.stepsList count];
return counter;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set up the cell...
// Pending
return cell;
}
- (void)stepDetailsViewControllerDidDone:(StepDetailsViewController *)controller
{
[self.workout.stepsList addObject:controller.step];
NSInteger counter = [self.workout.stepsList count];
[self.stepsListTableView beginUpdates];
NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:(counter-1) inSection:0]];
[self.stepsListTableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[self.stepsListTableView endUpdates];
[self.stepsListTableView reloadData];
}
(…)
Also in the storyboard, I have setup the outlets delegate and dataSource to be the controller view.
Any idea ?
Regards,
JoanBa
I have solved the issue. I have discovered using debugger that method reloadData was called for a different UITableView than the one initialized in viewDidLoad.
I reviewed the UITableView settings in storyboard, which aparently were correct but I have deleted them and created again. Now it works.
In UIViewController header I have the line
#property (nonatomic, retain) IBOutlet UITableView *stepsListTableView;
and in implementation I have commented lines
//self.stepsListTableView.delegate = self;
//self.stepsListTableView.dataSource = self;
And, of course, in storyboard I have defined for the UITableView the following relationships:
Outlets: dataSource, delegate --> UIViewController
Referencing outlet: UITableView --> UIVIewController
That's it !!
You may have the table view set to static content. Select the UITableView in Storyboard and in the "Attributes Inspector" section of the menu on the right of screen select the "Content" field under the "Table View" header and set the value to "Dynamic Prototypes".
Screenshot for clarity:
This little trick caught me out several times when I was starting out.

Resources