Value stored to 'cell' is never read - objective-c

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *customCell_Identifier = #"CustomCell";
ThreePartitionCells *cell = (ThreePartitionCells *)[tableView dequeueReusableCellWithIdentifier:customCell_Identifier];
if (cell == nil)
{
cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ThreePartitionCells" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
NSLog(#"%#", [arrActivityList objectAtIndex:[indexPath row]]);
NSString *strTemp = [NSString stringWithFormat:#"%#-%#", [[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:#"ITEMS"] objectForKey:#"Area"] objectForKey:#"AREANAME"] objectForKey:#"text"], [[[[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:#"ITEMS"] objectForKey:#"Area"] objectForKey:#"ITEMS"] objectForKey:#"Bin"] objectForKey:#"BIN_BARCODE"] objectForKey:#"text"] ];
cell.lblProductName.text = strTemp;
cell.lblExpectedCount.text = [[[arrActivityList objectAtIndex:[indexPath row]]objectForKey:#"ProductName"]objectForKey:#"text" ];
cell.lblCounted.text = [[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:#"Status"] objectForKey:#"text"];
[cell.lblProductName setFont:[UIFont fontWithName:#"Helvetica" size:13.0]];
[cell.lblCounted setFont:[UIFont fontWithName:#"Helvetica" size:13.0]];
return cell;
}
I get warning while analyzing project like this "value stored to 'cell' is never read" .Well! code is using the cell but outside of that if block. I want to silent this warning!
Can anybody help me for this?
Thanks in advance :)

The problem here:
if (cell == nil)
{
cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ThreePartitionCells" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
You initialize the cell from custom class, and then you assigned to the cell from a nib, so that you lose control of the first cell and you have not used the first cell.
Try this:
if (!cell){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ThreePartitionCells"
owner:self
options:nil];
for (id obj in nib) {
if ([obj isKindOfClass:[ThreePartitionCells class]]) {
cell = (ThreePartitionCells *)obj;
break;
}
}
}
or:
if (!cell){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ThreePartitionCells"
owner:self
options:nil];
cell = nib[0];
}
or:
if (!cell){
cell = [[[ThreePartitionCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifierr] autorelease];
}

Related

Tableview Cell Images Moving To Different Positions When Scrolling

When I scroll the table view my images move to the wrong cells. I have set some conditions when an image should be showing or not showing, but no matter what I have tried they just keep moving. My code below.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = #"myCell";
CustomTableView *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
if (self.view.frame.size.height == 736) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCelliPhone6+" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else if (self.view.frame.size.height == 667){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCelliPhone6" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else if (self.view.frame.size.height == 568) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCelliPhone5" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCelliPad" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomTableView" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
}
MusicFileInfo *musicFileInfo = [mMusicInfoArray objectAtIndex:indexPath.row];
cell.trackName.text = musicFileInfo.mDesc;
cell.trackName.backgroundColor = [UIColor clearColor];
cell.trackName.font = [UIFont fontWithName:#"AvenirNext-Regular" size:13.0];
if (songPlaying == indexPath.row && mAudioPlayer.isPlaying) {
[cell.playButton setBackgroundImage:[UIImage imageNamed:#"pauseBtn.png"] forState:UIControlStateNormal];
[cell.playButton addTarget:self action:#selector(pause:) forControlEvents:UIControlEventTouchUpInside];
cell.playButton.tag = indexPath.row;
}
else {
[cell.playButton setBackgroundImage:[UIImage imageNamed:#"playBtn.png"] forState:UIControlStateNormal];
[cell.playButton addTarget:self action:#selector(playPreview:) forControlEvents:UIControlEventTouchUpInside];
cell.playButton.tag = indexPath.row;
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:#"pack%li", (long)indexPath.row]] == true || [[NSUserDefaults standardUserDefaults] boolForKey:#"unlockAllTracks"] == true) {
cell.rightImage.image = nil;
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:#"pack%li", (long)indexPath.row]] == false) {
if (indexPath.row <= 4) {
cell.rightImage = nil;
} else
[cell.rightImage setImage:[UIImage imageNamed:#"iapBtnStore.png"]];
}
cell.backgroundColor = [UIColor colorWithRed:231.0f/255.0f green:235.0f/255.0f blue:236.0f/255.0f alpha:1];
cell.tag = indexPath.row;
return cell;
}
The play button and track label are fine, they work as they should, but the rightImage is where the problem is.
The first 5 cells should not have an image on first load, on second load the first 5 cells should have a star image and the rest of the cells should have a padlock image. After an IAP has been made, depending on the indexpath.row then that padlock image should no longer be there.
I am checking that with NSUserDefaults.
I hope I have explained properly.
Thanks for any help
UITableViewCells get reused to increase memory efficiency and performance, so you need to "reset" any elements that might change based on the item's state or it might re-appear somewhere else in the list.
Hence "reusable":
[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
// load nib if needed
}
cell.rightImage = nil; // always reset image

How Block or disable someones Customs Cells From Tableview with data from plist?

well I have 2 plist files:
And:
My StoryBoard is:
the problem is when in my "Inicio" viewcontroller load data from the plist, I want Disable the cells when have the ENABLE=NO property & Enable the cells with ENABLE = YES, when I push or click in the cell, then go to the next view controller "PERSONAS" in this view controller load the 2nd Plist and in the same case I want go to the "DETALLE"viewcontroller only with the enabled cells that have ENABLED YES from plist.
for each viewdidload Im use:
NSString *myListPath = [[NSBundle mainBundle] pathForResource:#"MainMenuList" ofType:#"plist"];
mainMenu = [[NSArray alloc]initWithContentsOfFile:myListPath];
NSLog(#"%#",mainMenu);
NSString *myListPath = [[NSBundle mainBundle] pathForResource:#"PersonasList" ofType:#"plist"];
Personas = [[NSArray alloc]initWithContentsOfFile:myListPath];
NSLog(#"%#",Personas);
And for show the tableview in the custom cell Im use:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"CustomCell";
NSLog(#"CARGANDO CELDAS");
MainMenuCell *cell = (MainMenuCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCelliPhone" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//CustomCell*cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.Enabled.text = [[mainMenu objectAtIndex:indexPath.row]objectForKey:#"ENABLE"];
cell.TitleLabel.text = [[mainMenu objectAtIndex:indexPath.row]objectForKey:#"NAME"];
cell.ImageImageView.image = [UIImage imageNamed:[[mainMenu objectAtIndex:indexPath.row]objectForKey:#"IMAGE"]];
if ([cell.Enabled.text isEqualToString:#"NO"])
{
NSLog(#"%#",cell.Enabled.text);
cell.userInteractionEnabled = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selected = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
in the Persona view controller I use the same code but not working, all customs cells are enabled, how can I fix that?, or am I wrong in something? or I did Forget Something please help guys!!
in the Simulator run in that way for ENABLE:
But I dont wanna the cells with ENABLE NO run!!:
Please help guys, im using XCODE 5 DP6, for iOS7, how is the best way for solve this!!!
THANKS!!!!
for many intents, finally fix this!! well in each viewcontroller the code whit solve this is like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"MainMenuCell";
NSLog(#"CARGANDO CELDAS");
MainMenuCell *cell = (MainMenuCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"MainMenuCelliPhone" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//MainMenuCell*cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.Enabled.text = [[mainMenu objectAtIndex:indexPath.row]objectForKey:#"Enabled"];
cell.TitleLabel.text = [[mainMenu objectAtIndex:indexPath.row]objectForKey:#"Title"];
cell.ImageImageView.image = [UIImage imageNamed:[[mainMenu objectAtIndex:indexPath.row]objectForKey:#"Image"]];
//cell.ImageImageView.image = [[mainMenu objectAtIndex:indexPath.row]objectForKey:#"Image"];
if ([[[mainMenu objectAtIndex:indexPath.row]objectForKey:#"Enabled"] isEqualToString:#"NO"])
{
NSLog(#"%#",cell.Enabled.text);
cell.userInteractionEnabled = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selected = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.ImageImageView.image = [UIImage imageNamed:#"NO.png"];
}
else
{
cell.ImageImageView.image = [UIImage imageNamed:#"YES.png"];
}
return cell;
//------------------------------------------//
// THANKS anyway //
// GRETTINGS FROM BOLIVIA //
// ROCK ON!!!! n_n' //
//------------------------------------------//
}

Custom UITableViewCell re-creating itself

Really need help. I've looked everywhere but still i cant find an answer. So, when i scroll my UITableView with custom cells in it its recreating cell each time I see it. As the result it lowers my performance significantly.
my method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"CellWithViewForProduct";
ProductCell *cell = (ProductCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
ProductDataStruct *dataStruct = [self.arrayData objectAtIndex:indexPath.row];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"productCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[ProductCell class]])
{
cell = (ProductCell *)currentObject;
break;
}
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.roundingIncrement = [NSNumber numberWithDouble:0.01];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSString *price = [formatter stringFromNumber:[NSNumber numberWithFloat:(dataStruct.price.floatValue * [[[NSUserDefaults standardUserDefaults] objectForKey:#"CurrencyCoefficient"] floatValue])]];
NSString *priceString = [NSString stringWithFormat:#"%# %#", price, [[NSUserDefaults standardUserDefaults] objectForKey:#"Currency"]];
cell.productPrice.text = priceString;
cell.productDescription.text = [NSString stringWithFormat:#"%#", dataStruct.descriptionText];
cell.productTitle.text = [NSString stringWithFormat:#"%#", dataStruct.title];
if (dataStruct.hit.integerValue == 1)
{
[cell.productImage.layer addSublayer:[hitView layer]];
}
else
if (dataStruct.hit.integerValue == 2)
[cell.productImage.layer addSublayer:[newsItemView layer]];
if (!dataStruct.image)
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO && dataStruct.link)
{
[self startIconDownload:dataStruct forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
//cell.productImage.image = [UIImage imageNamed:#"Placeholder.png"];
// if a download is deferred or in progress, return a loading screen
cell.productImage.alpha = 0;
[cell.productImageLoadingIndocator startAnimating];
}
else
{
if (self.didLoad)
{
cell.productImage.alpha = 0;
}
[cell.productImageLoadingIndocator stopAnimating];
cell.productImage.image = dataStruct.image;
[self imageAnimation: cell.productImage];
}
NSLog(#"WAZAAA");
return cell;
}
This entire chunk of code:
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"productCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[ProductCell class]])
{
cell = (ProductCell *)currentObject;
break;
}
}
seems wrong to me. Above it,
ProductCell *cell = (ProductCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
should be sufficient to get you a cell to use.
first create a #property (nonatomic, assign) IBOutlet ProductCell *prodCell; in the .h
Then in the .m you just need this
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"CellWithViewForProduct";
ProductCell *cell = (ProductCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"productCell" owner:self options:nil];
cell = prodCell;
self.prodCell = nil;
NSLog(#"WAZAAA"); //Now it will only be called when a new cell is created.
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.roundingIncrement = [NSNumber numberWithDouble:0.01];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSString *price = [formatter stringFromNumber:[NSNumber numberWithFloat:(dataStruct.price.floatValue * [[[NSUserDefaults standardUserDefaults] objectForKey:#"CurrencyCoefficient"] floatValue])]];
NSString *priceString = [NSString stringWithFormat:#"%# %#", price, [[NSUserDefaults standardUserDefaults] objectForKey:#"Currency"]];
cell.productPrice.text = priceString;
cell.productDescription.text = [NSString stringWithFormat:#"%#", dataStruct.descriptionText];
cell.productTitle.text = [NSString stringWithFormat:#"%#", dataStruct.title];
if (dataStruct.hit.integerValue == 1)
{
[cell.productImage.layer addSublayer:[hitView layer]];
}
else
if (dataStruct.hit.integerValue == 2)
[cell.productImage.layer addSublayer:[newsItemView layer]];
if (!dataStruct.image)
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO && dataStruct.link)
{
[self startIconDownload:dataStruct forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
//cell.productImage.image = [UIImage imageNamed:#"Placeholder.png"];
// if a download is deferred or in progress, return a loading screen
cell.productImage.alpha = 0;
[cell.productImageLoadingIndocator startAnimating];
}
else
{
if (self.didLoad)
{
cell.productImage.alpha = 0;
}
[cell.productImageLoadingIndocator stopAnimating];
cell.productImage.image = dataStruct.image;
[self imageAnimation: cell.productImage];
}
NSLog(#"WAZAAA"); //Here doesn't make any sense, the cell is returned for being displayed, this doesn't mean it's being created.
return cell;
}

Use of undeclared identifier 'cell'

i'm using a custom tablecell but i have a problem with parsing JSON in my uilabel i'm using the code below, this works great. To put something in my UILabel i simple do
cell.One.text = #"xx";
/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = #"CustomCellIdentifier ";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell"
owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *)oneObject;
}
return cell;
}
But when i try to parse something i normally do
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* lastgame = [json objectForKey:#"items"];
NSDictionary* game = [lastgame objectAtIndex:0];
cell.One.text = [NSString stringWithFormat:#"%#",
[strijd objectForKey:#"One"]
];
}
But on this line i'm recieving an error: (Use of undeclared identifier 'cell') does anyone now how to fix thix?
cell.One.text = [NSString stringWithFormat:#"%#",
[strijd objectForKey:#"One"]
];
cell.One.text = [NSString stringWithFormat:#"%#",
[strijd objectForKey:#"One"]
];
your cell isn't declared in this methode, you have to do this in cellForRowAtIndexPath:
after you declare your cell with: CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];

web view not updating when pushed from table view

My current app consists of Navigation with Tabs, then a Table View in between, from the Table Rows when selected a Detail View is pushed. The issue I'm having is when I select a row it pushes to the Detail View and loads the html file in the Web View. However, when I navigate back and then select another row, it loads the same html from the previous selection. The only thing that stays relevant is the Title in the Navigation Title Bar.
Is this poor memory management on my part (I'm new to ObjC.. like only a week) or did I miss a step? I think me grabbing NSString *navDate = self.title; is my problem. Everything else basically works otherwise. Anyways, be gentle and thanks. :$
Table Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellID = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if(cell == nil){
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellID];
}
cell.textLabel.font = [UIFont systemFontOfSize:15];
cell.textLabel.text = [self.dateList objectAtIndex: [indexPath row]];
return cell;
}
Row Push
(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if(self.aTextController == nil){
ATextController *aTextDetail = [[ATextController alloc] initWithNibName:#"ArchiveData" bundle:nil];
self.aTextController = aTextDetail;
[aTextDetail release];
}
aTextController.title = [NSString stringWithFormat:#"%#", [dateList objectAtIndex:row]];
SLESDAppDelegate *delegate = (SLESDAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:aTextController animated:YES];
}
DetailView
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *navDate = self.title;
NSString *null = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#", navDate] ofType:#"html"];
if(null != nil){
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#", navDate] ofType:#"html"]isDirectory:NO]]]; }
else {
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"error" ofType:#"html"]isDirectory:NO]]];
}
}
Since you are retaining the instance of ATextController and reusing it, you will have to execute the following snippet in viewWillAppear: -
NSString *navDate = self.title;
NSString *null = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#", navDate] ofType:#"html"];
if(null != nil){
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#", navDate] ofType:#"html"]isDirectory:NO]]]; }
else {
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"error" ofType:#"html"]isDirectory:NO]]];
}
The reason being that viewDidLoad is called once when the view controller loads its view. viewWillAppear: will be called every time the view is about to come on screen.