iOS 7 UITableViewCell textLabel not retaining text - ios

This has been driving me crazy and not really sure whats going on. I have a UITableView and I'm populating the content of the UITableViewCells like so
- (UITableViewCell *)tableView:(UITableView *)a_tableView cellForRowAtIndexPath:(NSIndexPath *)a_indexPath
{
NewsItemCell * cell = (NewsItemCell *)[a_tableView dequeueReusableCellWithIdentifier:#"NewsItemCell"];
if(cell == nil)
{
cell = [[[NewsItemCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)] autorelease];
}
if(!m_isLoading)
{
NewsFeed * feed = [NewsFeed sharedNewsFeed];
NewsEntry * entry = [[feed feedEntries] objectAtIndex:[a_indexPath row]];
[cell setNewsEntry:entry];
}
else
{
if([a_indexPath row] < [m_visibleCells count])
{
return [m_visibleCells objectAtIndex:[a_indexPath row]];
}
}
return cell;
}
The line that contains [cell setNewsEntry:entry] takes the NewsEntry object and sets the cells textLabel.text to a string contained in entry. This works fine in iOS 6 but in iOS 7 the labels aren't showing the text.
- (void)setNewsEntry:(NewsEntry *)a_newsEntry
{
self.textLabel.text = a_newsEntry.title;
self.detailTextLabel.text = a_newsEntry.summary;
self.imageView.image = [self getIconForFeedType:[a_newsEntry feedType]];
}
I've done some poking around and in setNewsEntry and if I set self.textLabel.text to a string literal e.g. #"hello" then it works fine. I've also don't a lot of NSLogs inside of setNewsEntry to make sure that a_newsEntry actually has a valid title and summary properties, it does but for some reason the textLabel doesn't seem to be retaining them.
At first I was thinking that this was some memory issue with NewsEntry object but it doesn't make sense to me why this would be the case in iOS 7 and not iOS 6. Shouldn't the textLabel.text property retain the NSString that it gets set to?
If anyone has any ideas as to why this is happening please let me know and I can provide answers to any questions you have.
Thank you.
EDIT: NewsEntry Interface
#interface NewsEntry : NSObject
{
NSString * m_title;
NSString * m_summary;
NSString * m_published;
NSString * m_updated;
NSString * m_link;
int m_feedType;
}
#property (nonatomic, readonly) NSString * title;
#property (nonatomic, readonly) NSString * summary;
#property (nonatomic, readonly) NSString * published;
#property (nonatomic, readonly) NSString * updated;
#property (nonatomic, readonly) NSString * link;
#property (nonatomic, readonly) int feedType;
- (NSDictionary *)properties;
- (NewsEntry *)initWithProperties:(NSDictionary *)a_properties;
- (NSComparisonResult)compareEntry:(NewsEntry *)entry;
#end

Where you able to resolve it?
I have a similar issue where the detailTextLabel does not get updated on iOS7 whereas it works fine on iOS6. In my case, if I present another view on top and than go back to the tableview, I see the label updated already.

Related

How to make a group of labels to align themselves in iOS?

Im relatively new to iOS development, and my constraints skill is at a basic level. I'm having a group of labels like so
However the Company Name and Address Line 2 are not always required so they are hidden in some cases, but when they are I don't know how to push the other labels up so that they fill the space created by the hidden labels.
Much appreciated if you guys can give a solution on this.
HI Joel why don't you try stack view inside table view cell and set
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
and stackview and tableview will handle everything for you.
If you are using constraints then for instance the top label should have leading, trailing and top to superview.
Now this label will have its height depending on its font and text. If its text is empty then its height will be zero which you basically want.
Now next label is best to have leading and trailing to superview (or the label above it) and then vertical spacing to label before it. This means it will be just below the first one. And if first one has no text it will be on top.
Now do the same for all other labels one blow the other using vertical offset constraint.
Note for what you are doing it seems more appropriate to use an UITableView or maybe stack view. But if you want constraints then this is the procedure.
If things get complicated you can also drag constraints into your code and manipulate them manually.. For instance:
self.companyNameHeightConstraint.constant = myDataMode.companyName.isEmpty == true ? 0.0 : 50.0
EDIT: Since it is a bit unclear if fields are displayed depending on some external flags or if these strings are shown if they exist I am adding a minimum table view procedure with external flags:
#interface TableViewController () <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, strong) NSString *name;
#property (nonatomic, strong) NSString *lastName;
#property (nonatomic, strong) NSString *companyName;
#property (nonatomic, strong) NSString *address1;
#property (nonatomic, strong) NSString *address2;
#property (nonatomic, readonly) BOOL isAddress2Shown;
#property (nonatomic, readonly) BOOL isCompanyNameShown;
#end
#implementation TableViewController
- (NSArray *)generateDsiaplyableStrings {
NSMutableArray *array = [[NSMutableArray alloc] init];
if(self.name) [array addObject:self.name];
if(self.lastName) [array addObject:self.lastName];
if(self.companyName && self.isCompanyNameShown) [array addObject:self.companyName];
if(self.address1) [array addObject:self.address1];
if(self.address2 && self.isAddress2Shown) [array addObject:self.address2];
return array;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self generateDsiaplyableStrings].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *items = [self generateDsiaplyableStrings];
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
cell.textLabel.text = items[indexPath.row];
return cell;
}
#end

Customized UITableViewCell reuse with childviewcontroller issue

I have create a UITableView With a Customized TableViewCell,
#import <UIKit/UIKit.h>
#import "Equipment.h"
#import "MCStepperViewController.h"
#class EquipmentCell;
#protocol EquipmentCellDelegate <NSObject>
- (void)EquipmentCell:(EquipmentCell *)cell didChangeStepperValue:(int)stepperValue indexPath:(NSIndexPath*)indexPath;
#end
#interface EquipmentCell : UITableViewCell <MCStepperDelegate>
#property (nonatomic, strong) UIImageView* eqiupmentImage;
#property (nonatomic, strong) UILabel* Title;
#property (nonatomic, strong) UILabel* details;
#property (nonatomic, strong) UILabel* prices;
#property (nonatomic, strong) MCStepperViewController* stepper;
#property (nonatomic, weak) id <EquipmentCellDelegate> delegate;
#property (nonatomic, assign) NSIndexPath* indexPath;
-(void)setContent:(Equipment*)equip;
-(void)setAmount:(int)eq_amount;
#end
The customized cell owns a stepperview controller, and I add the stepperViewController.view to the content view of the cell.
The stepperViewController has a textField and two buttons as strong properties.
The confusing part is, when I scroll the table view, the table cells are ready for reuse process.
The property views of the cell works well, but the view of stepperViewController, which is the subview of the contentView, is becoming duplicate.
Although I have set cell.stepper.view.textField to the right value, but it still doesn't work.
Is there any good solution? I don't think disable reusability is a good attempt.
Thank you very much!
EDIT:
The cellForRowAtIndexPath method:
else if (tableView == _subTable)
{
EquipmentCell *cell = [tableView dequeueReusableCellWithIdentifier:#"detailTable" forIndexPath:indexPath ];
if(!cell)
{
cell = [[EquipmentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"detailTable"];
}
cell.indexPath = indexPath;
Equipment* item = [[[_goodsList objectAtIndex:indexPath.section] objectForKey:#"data"] objectAtIndex:indexPath.row];
cell.delegate = self;
[cell setContent:item];
if (countDic) {
if ([countDic objectForKey:[NSString stringWithFormat:#"%lu", (indexPath.section*100)+(indexPath.row)]]) {
[cell setAmount:(int)[[countDic objectForKey:[NSString stringWithFormat:#"%lu", (indexPath.section*100)+(indexPath.row)]] integerValue]];
}
else
{
[cell setAmount:0];
}
}
return cell;
}
I tried to assign the textfield.text in cell class, but is doesn't work.
- (void)setAmount:(int)eq_amount
{
_stepper.amount = eq_amount;
_stepper.amountText.text = [NSString stringWithFormat:#"%d", eq_amount];
if (eq_amount == self.stepper.min) {
_stepper.minusButton.hidden = YES;
_stepper.amountText.hidden = YES;
}
}
Check where you add your stepperViewController.view to the content view of the cell.
You want to support view recycling for your tableview cell. So as soon as your cell1 is not visible anymore and data 2 needs a cell (cellForRowAtIndexPath gets called), this reused cell will be cell 1. Instead of data1 cell1 now displays data2. If you add the stepperViewController.view in the cellForRowAtIndexPath function, there will be the view added for data1. now if cell1 isn't visible anymore and should be used for data2 you should check if you add the stepperViewController.view again.
Instead of simply adding the view, you could check if there is already a stepperViewController.view in you cell's subviews and remove or reuse it.

Table view cells lose their order

Goal
I'm trying to create a table view like Instegram's home screen.
I've made a custom cell, I'm initialising it with data, the cell suppose to hold the "Post".
Logic
I save each cell in a NSMutableDictionary , the key is the index of the posts order and the value is the post it self.
Current Result
I scroll down, and everything is fine. The order you see is post1, post2, post3...post 8 but when I scroll up, everything mess up and the post order is post8, post6, post7, post8, post5... You get the point.
(Before asking here I tried doing it with small objects - a REGULAR ! (not custom) cell containing only strings.
for some reason it worked ! the order was perfect.)
Code
this is my UITableViewController - my "Home" screen "cellForRow" Method.
if we scroll up and the index of the Tableview is alrdy have been initialised, I pull the post form the dictionary.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *PC = #"PostCell";
PostCell *Pcell = [tableView dequeueReusableCellWithIdentifier:PC forIndexPath:indexPath];
NSString *key = [[NSString alloc] initWithFormat:#"%i", indexPath.section];
NSLog(#"Cell %i", indexPath.section);
// Checking if alrdy visted this indexpath.
if (![_allcells objectForKey:key]) {
[self setPostUserName:[[NSString alloc] initWithFormat:#"username: %i", indexPath.section]:Pcell];
// Saving a postcell I wont return, just to save in a dictionary.
// When we get here again it will get another pointer like that my object wont change.
PostCell* toSave = [[PostCell alloc] init];
// saving it with current post data.
[self copyPost:toSave :Pcell];
[_allcells setObject:toSave forKey:key];
}
else {
// Copying post daya
[self copyPost:Pcell :[_allcells objectForKey:key]];
}
NSLog(#"Cell %i Returning: %#", indexPath.section, Pcell.userName.text);
return Pcell;
}
// Check if it reached the end
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
if (endScrolling >= scrollView.contentSize.height)
{
NSDictionary *temparr = [[NSDictionary alloc] initWithDictionary:_allcells];
[self.tableView reloadData];
_allcells = [[NSMutableDictionary alloc] initWithDictionary:temparr];
}
}
and this is my PostCell.h , so you can see the attributes.
#interface PostCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UIImageView *profilePic;
#property (strong, nonatomic) IBOutlet UILabel *userName;
#property (strong, nonatomic) IBOutlet UILabel *checkIn;
#property (strong, nonatomic) IBOutlet UILabel *uploadedAgo;
#property (strong, nonatomic) IBOutlet UIImageView *mainPic;
#property (strong, nonatomic) IBOutlet UILabel *likes;
#property (strong, nonatomic) IBOutlet UILabel *participants;
#end
By the way, if you got a project example that has a result similar to Instagram home screen it would be great if you can link me to it!
You shouldn't store references to the cells, since they are being reused by the tableview when they leave the screen. At the moment everything works fine for you while scrolling down the first time, because you create the cells new. On scrolling up, you get the stored reference which now points to one of the newly created cells, so things look messed up.
What you should do is just populating the reused cells with the right data and only create them if needed. Like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *PC = #"PostCell";
PostCell *Pcell = (PostCell*)[tableView dequeueReusableCellWithIdentifier:PC forIndexPath:indexPath];
// feed the needed data to the cell
return Pcell;
}
Not sure why you are accessing only indexPath.section since usually you would populate the table with multiple cells per section, using indexPath.row.
Okay, I found out the mistake, Because I was first I was saving the id of each Post and than took it out of the dictionary it didn't work.
than I was trying to only save the attributes of the post by creating a "fake" postCell and saving the attribues of the original cell in the fake cell and than took it out of the array and made the cell copy ONLY the attributes of the cell I just took out and it didn't work.
why? because no matter what I was saving a POINTER ! to those fields !.
I've created a class which was ment to save my desired data that's the class I entered my dictionary.
now each time I dequeue a cell, I load it with the data of the index I'm at. :)
So nice to finally solve it and to learn something new, thanks for giving me leads !
A UITableView works best with an array. Also an array will stay in order as it is indexed, while dictionaries have no index, and thus will not retain order. Also separate cells of the same type, in this case PostCell, should not have different sections, but instead different rows. Use section to separate different categories of cells.
Another tip; NSMutableDictionary takes up more memory than an NSDictionary. Once you have set everything in your NSMutableDictionary, store it in an NSDictionary. If you want to modify it in the future, copy it back into an NSMutableDictionary, modify it, and then store it again as an NSDictionary.
#property (strong, nonatomic) NSDictionary *post;
// To create an NSDictionary
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:#"74 degrees" forKeyPath:#"weather"];
post = tempDict;
// To modify an NSDictionary
tempDict = [[NSMutableDictionary alloc] initWithDictionary:post];
[tempDict removeObjectForKey:#"weather"];
post = tempDict;
Then store it in an array.
#property (strong, nonatomic) NSArray *allPosts;
// NSMutableArray takes up more memory than NSArray
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:allPosts];
[tempArray addObject:post];
allPosts = tempArray;
Finally, display it in your tableview.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *PC = #"PostCell";
PostCell *pCell = [tableView dequeueReusableCellWithIdentifier:PC];
if (!cell) {
pCcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PC];
}
NSDictionary *currentPost = [allPosts objectAtIndex:indexPath.row];
// Instead of having post1, post2, post3 and so forth, each post is now in currentPost. If there are 10 posts, then this function will run 10 times. Just write the code as if you are handling one post, and the UITableView will automatically fill in the rest of the posts for you.
return cell;
}

UITableViewController: Objects properties deallocated

I'm using a UITableViewController to display a list of articles from a web service. Once the data is retrieved this delegate method is called:
-(void)itemsDownloaded:(NSArray *)items
{
// Set the items to the array
_feedItems = items;
// Reload the table view
[self.tableView reloadData];
}
I'm also using a custom cell so that the label's height varies, therefore displaying the whole of the article's title with the following code (followed this tutorial Table View Cells With Varying Row Heights):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"BasicCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell isKindOfClass:[CustomTableViewCell class]])
{
CustomTableViewCell *textCell = (CustomTableViewCell *)cell;
Article *article_item = _feedItems[indexPath.row];
NSString *fulltitle = article_item.Title;
// fulltitle = article_item.Cat_Name; // testing category name
if (article_item.Subtitle != nil && article_item.Subtitle.length != 0) {
fulltitle = [fulltitle stringByAppendingString:#": "];
fulltitle = [fulltitle stringByAppendingString:article_item.Subtitle];
}
textCell.lineLabel.text = fulltitle;
textCell.lineLabel.numberOfLines = 0;
textCell.lineLabel.font = [UIFont fontWithName:#"Novecento wide" size:12.0f];
}
}
- (CustomTableViewCell *)prototypeCell
{
NSString *cellIdentifier = #"BasicCell";
if (!_prototypeCell)
{
_prototypeCell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
return _prototypeCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self configureCell:self.prototypeCell forRowAtIndexPath:indexPath];
self.prototypeCell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tableView.bounds), CGRectGetHeight(self.prototypeCell.bounds));
[self.prototypeCell layoutIfNeeded];
CGSize size = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height+1;
}
The first issue is that the method forRowAtIndexPath is being called twice instead of once. Therefore if the _feeditems has 10 objects, the method is called 20 times. The second time the method is called I'm getting two properties (ID and Cat_Name) of the Article object null since of deallocation:
*** -[CFString retain]: message sent to deallocated instance 0x9c8eea0
*** -[CFNumber respondsToSelector:]: message sent to deallocated instance 0x9c8e370
This fires an EXC_BAD_ACCESS when trying to display the category name.
I'm not sure what can be the problem exactly, I've tried removing the code to vary the height of the labels to see if that was causing this problem by using this code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Retrieve cell
NSString *cellIdentifier = #"BasicCell";
UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Get article
Article *item = _feedItems[indexPath.row];
myCell.textLabel.text = item.Title;
return myCell;
}
The only difference was that the method was being called once meaning 10 times if _feeditems has 10 objects. But the Article's properties ID and Cat_Name were still being deallocated.
At the point of getting the data, all objects' properties in _feeditems are intact, nothing deallocated. I guess it's happening in cellForRowAtIndexPath or forRowAtIndexPath.
UPDATE
As suggested by #Ilya K. not calling configureCell:forRowAtIndexPath: from tableView:heightForRowAtIndexPath stopped the issue of having it being called twice. I've also tried having a property of feedItems. So far this was being set in the #interface of the Controller (TableViewController.m):
#interface TableViewController () {
HomeModel *_homeModel;
NSArray *_feedItems;
Article *_selectedArticle;
}
I've removed it from the interface and added it as a property (TableViewController.h):
#interface TableViewController : UITableViewController <HomeModelProtocol>
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (nonatomic, strong) CustomTableViewCell *prototypeCell;
#property(nonatomic) NSString *type;
#property(nonatomic) NSString *data;
#property(copy) NSArray *_feedItems;
#end
It's still giving deallocated messages though.
UPDATE 2
I've looked through the code using Instruments with a Zombie template (thanks to the answer of this question ViewController respondsToSelector: message sent to deallocated instance (CRASH)). This is the error I'm getting from Instruments:
Zombie Messaged
An Objective-C message was sent to a deallocated 'CFString (immutable)' object (zombie) at address: 0x10c64def0
All Release/Retain Event Types point to the following method, connectionDidFinishLoading, which is being used when the JSON data is retrieved from the web service and create Article objects for each article retrieved:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Create an array to store the articles
NSMutableArray *_articles = [[NSMutableArray alloc] init];
// Parse the JSON that came in
NSError *error;
// Highlighted in blue
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:_downloadedData options:kNilOptions error:&error];
NSArray *fetchedArr = [json objectForKey:#"result"];
// Loop through Json objects, create question objects and add them to our questions array
for (int i = 0; i < fetchedArr.count; i++)
{
NSDictionary *jsonElement = fetchedArr[i];
// Create a new location object and set its props to JsonElement properties
Article *newArticle = [[Article alloc] init];
newArticle.ID = jsonElement[#"ID"];
newArticle.Title = jsonElement[#"Title"];
newArticle.Subtitle = jsonElement[#"Subtitle"];
newArticle.Content = jsonElement[#"Content"];
newArticle.ImageUrl = jsonElement[#"ImageUrl"];
newArticle.Author = jsonElement[#"Author"];
newArticle.PostId = jsonElement[#"PostId"];
newArticle.ArticleOrder = jsonElement[#"ArticleOrder"];
newArticle.Cat_Id = jsonElement[#"CategoryId"];
// Highlighted in yellow
newArticle.Cat_Name = jsonElement[#"CategoryName"];
// Add this article object to the articles array
// Highlighted in yellow
[_articles addObject:newArticle];
}
// Ready to notify delegate that data is ready and pass back items
if (self.delegate)
{
[self.delegate itemsDownloaded:_articles];
}
}
I still can't figure out what is wrong though.
UPDATE 3
More testing on connectionDidFinishLoading I've removed the two properties that are being deallocated and no deallocated messages are shown. I don't know what's causing these two properties (ID and Cat_Name) to be deallocated, these are not being accessed from anywhere at this point.
You don't need to call to configureCell:forRowAtIndexPath: from tableView:heightForRowAtIndexPath: you should determine cell height using Article object with sizeWithAttributes:
Your prototypeCell function just creates unrelated empty cell of type CustomTableViewCell and there is no point of trying re-size it.
tableView:cellForRowAtIndexPath: called each time your tableview needs redraw, when you scroll for example. That means that your _feeditems array should be allocated and consistent to work with UITableView at any point of instance life time.
Also make sure you declare a property for _feeditems and assign data using this property.
Example:
#property (strong) NSArray *feeditems; or #property (copy) NSArray *feeditems;
in itemsDownloaded:
self.feeditems = items;
Finally solved the deallocated messages issue. While using Instruments with a Zombie template (using Instruments and Zombie template: ViewController respondsToSelector: message sent to deallocated instance (CRASH)) I found that this line:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:_downloadedData options:kNilOptions error:&error];
in the connectionDidFinishLoading method was causing this problem. I searched for NSJSONSerialization causing deallocation messages and I got the answer from this question Loading properties from JSON, getting "message sent to deallocated instance". The Article class had a few properties that were set to assign instead of strong:
#interface Article : NSObject
#property (nonatomic, assign) NSNumber *ID; // changed assign to strong
#property (nonatomic, strong) NSString *Title;
#property (nonatomic, strong) NSString *Subtitle;
#property (nonatomic, strong) NSString *Content;
#property (nonatomic, strong) NSString *ImageUrl;
#property (nonatomic, assign) NSNumber *PostId; // changed assign to strong
#property (nonatomic, strong) NSString *Author;
#property (nonatomic, assign) NSNumber *ArticleOrder; // changed assign to strong
#property (nonatomic, assign) NSNumber *Cat_Id; // changed assign to strong
#property (nonatomic, assign) NSString *Cat_Name; // changed assign to strong
#end
After changing the properties to strong, all deallocated messages stopped.
I know that this error seems to be very specific to each project and the cause of it may vary but in case someone has something similar, this is how I solved it.

UIPickerView reloadAllComponents doesn't get called

I have 2 table cells, based on what i have selected in my first cell, i have to refresh the second cell, when i click the second cell a container view with a picker is changed from hidden to unhidden state.
When I press the cell I have a method which gets called where after i get the new data I reload my picker, but that line of code doesn't get called, my picker isn't refreshed:
-(void)reloadData:(NSUInteger) path{
//NSUInteger path = (NSUInteger)self.parentVC.pozOras;
NSString *parcareFile = [[NSBundle mainBundle] pathForResource:#"Parcare"
ofType:#"plist"];
self.fisier = [NSArray arrayWithContentsOfFile:parcareFile];
////Log(#"reloadData:%#",self.fisier);
NSDictionary *infoOras = [self.fisier objectAtIndex:path];
// NSLog(#"reloadData:%#",infoOras);
NSLog(#"reloadData:%d",(NSInteger)path);
NSArray *zones = [infoOras valueForKey:#"Zone"];
self.zone = [zones valueForKey:#"name"];
NSLog(#"reloadData:%#",self.zone);
self.price = [zones valueForKey:#"price"];
NSLog(#"reloadData:%#",self.price);
self.time = [zones valueForKey:#"durationminutes"];
NSLog(#"reloadData:%#",self.time);
[self.listaCuZone reloadAllComponents];
}
All the data from the Output of NSLog is what is should be in the picker.
I have the property of the UIPickerView in the header file, everything seems to be in place. I really don't know why it doesn't get called.
#interface PickerZone : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>
#property (nonatomic, assign) FirstViewController *parentVC;
#property NSInteger zona;
#property NSUInteger path;
#property NSMutableArray *fisier;
#property NSMutableArray *zone, *price, *time;
#property (strong, nonatomic) IBOutlet UIPickerView *listaCuZone;
- (IBAction)doneButton:(id)sender;
- (void)reloadData:(NSUInteger)path;
#end
Here is where i call the method from:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0){
[self.listaZone viewForBaselineLayout].hidden = YES;
[self.listaOrase viewForBaselineLayout].hidden = NO;
}
else
{
PickerZone *pickerZone = [[PickerZone alloc]init];
[pickerZone reloadData:(NSUInteger)self.pozOras];
[pickerZone.listaCuZone reloadAllComponents];
[self.listaOrase viewForBaselineLayout].hidden = YES;
[self.listaZone viewForBaselineLayout].hidden = NO;
}
}
As you can see, i also try to reload the components here.
I have the delegate and the datasource also linked to the vc.
If i should post some more code please let me know, i really want to fix this.
Here is a screenshot of the storyboard: https://www.dropbox.com/s/4nkpz55zlcffh9w/Screenshot%202014-02-16%2019.31.24.png

Resources