Getting a "nested push animation can damage the navigation bar"

I am completely stuck. I was looking for answers to SO questions, and it looks like each problem has a different problem, since each "nested push animation can lead to a damaged navigation bar".

Keep in mind that I'm trying to teach myself how to encode iOS 7. Therefore, if some of my encoding methods are not perfect, I'm sorry, and please provide feedback. In any case, I am creating the Pokemon Trading Card Game Pokedex application, which shows the cards from the most recent sets. Everything works flawlessly, except when I select the first cell of the table on the main screen (XY Flash Fire). It will display the correct table data, but the title of the navigation bar is incorrect. Also, when I select a row, it will not go to the PokedexDetailViewController.

Again, all other table cells from the main screen work without problems. I also tried other fixes and classes that people posted here and github, but no one worked for me. I also recreated the entire FlashFireViewController and still have the same problems. Ensure that all code is pretty much identical to all other working controllers. It is also verified that segues come from the Set View Controller, opposite the cells. However, when it is in the Flash Fire View Controller, segues comes from a cell.

Cant post pics yet, so here is the album link to my screenshots: http://imgur.com/a/Dq9py

  • How my storyboard is set up.
  • The main screen after launching the application.
  • When I select the second cell (XY).
  • When I choose Mega Venusaur EX.
  • ** . (XY Flash Fire). , .
  • Butterfree , , . , , , .

TCGSetViewController.m, .

@interface TCGSetViewController ()

@end

@implementation TCGSetViewController{



 NSArray *thumbnailCell;
}

@synthesize tableView = _tableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    thumbnailCell = [NSArray arrayWithObjects:@"XYFlashFire.png", @"XYBaseSet.png", @"BWLegendaryTreasures", @"BWPlasmaBlast.png", @"BWPlasmaFreeze.png", @"BWPlasmaStorm.png", nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [thumbnailCell count];


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 61;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"PokemonSetCell";

    TCGSetCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[TCGSetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.setImage.image = [UIImage imageNamed:[thumbnailCell objectAtIndex:indexPath.row]];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Conditionally perform segues, here is an example:
    if (indexPath.row == 0)
    {
        [self performSegueWithIdentifier:@"showFlashFireSet" sender:self];
    }
    if (indexPath.row == 1)
    {
        [self performSegueWithIdentifier:@"showXYBaseSet" sender:self];
    }
    else
    {
        [self performSegueWithIdentifier:@"showLegendarySet" sender:self];
    }
}

FlashFireViewController.m, .

@interface FlashFireViewController ()

@end

@implementation FlashFireViewController{

    NSArray *pokemons;
    NSArray *searchResults;
}

@synthesize tableView = _tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];


    Pokemon *caterpie = [Pokemon new];
    caterpie.name = @"Caterpie";
    caterpie.hitPoints = @"40 HP";
    caterpie.setNumber = @"1/106";
    caterpie.imageFile = @"1-caterpie.jpg";
    caterpie.rarity = @"COMMON";

    Pokemon *metapod = [Pokemon new];
    metapod.name = @"Metapod";
    metapod.hitPoints = @"70 HP";
    metapod.setNumber = @"2/106";
    metapod.imageFile = @"2-metapod.jpg";
    metapod.rarity = @"UNCOMMON";

    Pokemon *butterfree = [Pokemon new];
    butterfree.name = @"Butterfree";
    butterfree.hitPoints = @"130 HP";
    butterfree.setNumber = @"3/106";
    butterfree.imageFile = @"3-butterfree.jpg";
    butterfree.rarity = @"RARE";

    Pokemon *pineco = [Pokemon new];
    pineco.name = @"Pineco";
    pineco.hitPoints = @"60 HP";
    pineco.setNumber = @"4/106";
    pineco.imageFile = @"4-pineco.jpg";
    pineco.rarity = @"COMMON";

    Pokemon *seedot = [Pokemon new];
    seedot.name = @"Seedot";
    seedot.hitPoints = @"50 HP";
    seedot.setNumber = @"5/106";
    seedot.imageFile = @"5-seedot.jpg";
    seedot.rarity = @"COMMON";

    Pokemon *nuzleaf = [Pokemon new];
    nuzleaf.name = @"Nuzleaf";
    nuzleaf.hitPoints = @"80 HP";
    nuzleaf.setNumber = @"6/106";
    nuzleaf.imageFile = @"6-nuzleaf.jpg";
    nuzleaf.rarity = @"UNCOMMON";

    Pokemon *shiftry = [Pokemon new];
    shiftry.name = @"Shiftry";
    shiftry.hitPoints = @"140 HP";
    shiftry.setNumber = @"7/106";
    shiftry.imageFile = @"7-shiftry.jpg";
    shiftry.rarity = @"RARE";

    Pokemon *roselia = [Pokemon new];
    roselia.name = @"Roselia";
    roselia.hitPoints = @"60 HP";
    roselia.setNumber = @"8/106";
    roselia.imageFile = @"8-roselia.jpg";
    roselia.rarity = @"COMMON";

    Pokemon *roserade = [Pokemon new];
    roserade.name = @"Roserade";
    roserade.hitPoints = @"90 HP";
    roserade.setNumber = @"9/106";
    roserade.imageFile = @"9-roserade.jpg";
    roserade.rarity = @"UNCOMMON";

    Pokemon *maractus = [Pokemon new];
    maractus.name = @"Maractus";
    maractus.hitPoints = @"90 HP";
    maractus.setNumber = @"10/106";
    maractus.imageFile = @"10-maractus.jpg";
    maractus.rarity = @"UNCOMMON";

    pokemons = [NSArray arrayWithObjects:caterpie, metapod, butterfree, pineco, seedot, nuzleaf, shiftry, roselia, roserade, maractus, nil];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [searchResults count];

    } else {
        return [pokemons count];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *pokemonTableIdentifier = @"PokemonTableCell";

    TCGPokedexCell *cell = (TCGPokedexCell *)[self.tableView dequeueReusableCellWithIdentifier:pokemonTableIdentifier];

    if (cell == nil)
    {
        cell = [[TCGPokedexCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pokemonTableIdentifier];
    }


    Pokemon *pokemon = [pokemons objectAtIndex:indexPath.row];
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        pokemon = [searchResults objectAtIndex:indexPath.row];
    } else {
        pokemon = [pokemons objectAtIndex:indexPath.row];
    }
    cell.pokemonLabel.text = pokemon.name;
    cell.pokemonNum.text = pokemon.setNumber;
    cell.thumbnailImageView.image = [UIImage imageNamed:pokemon.imageFile];
    cell.pokemonHP.text = pokemon.hitPoints;
    cell.pokemonRarity.text = pokemon.rarity;

    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 61;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"showPokedexDetail"]) {
        NSIndexPath *indexPath = nil;
        Pokemon *pokemon = nil;

        if (self.searchDisplayController.active) {
            indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
            pokemon = [searchResults objectAtIndex:indexPath.row];
        } else {
            indexPath = [self.tableView indexPathForSelectedRow];
            pokemon = [pokemons objectAtIndex:indexPath.row];
        }

        PokedexDetailViewController *destViewController = segue.destinationViewController;
        destViewController.pokemon = pokemon;
    }
}

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
    searchResults = [pokemons filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}



@end

, :

2014-07-08 12:38:18.409 TCG Pokedex[37666:60b] nested push animation can result in corrupted navigation bar
2014-07-08 12:38:18.849 TCG Pokedex[37666:60b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2014-07-08 12:38:22.222 TCG Pokedex[37666:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'
*** First throw call stack:
+4
2

, , tableView:didSelectRowAtIndexPath TCGSetViewController.m.

if, if else. indexPath.row == 0 if , [self performSegueWithIdentifier:@"showFlashFireSet" sender:self]. if else. . indexPath.row 0, else, segue.

, , ,

if (indexPath.row == 0)
{
    [self performSegueWithIdentifier:@"showFlashFireSet" sender:self];
}
else if (indexPath.row == 1) // notice the else on this line
{
    [self performSegueWithIdentifier:@"showXYBaseSet" sender:self];
}
else
{
    [self performSegueWithIdentifier:@"showLegendarySet" sender:self];
}

, switch:

NSString *segueID = nil;
switch (indexPath.row) {
    case 0:
        segueID = @"showFlashFireSet";
        break;
    case 1:
        segueID = @"showXYBaseSet";
        break;
    default:
        segueID = @"showLegendarySet";
        break;
}
[self performSegueWithIdentifier:segueID sender:self];

P.S.:

iOS 5 6 7 -, dequeueReusableCellWithIdentifier:forIndexPath: , cell == nil ( , iOS),

, dequeueReusableCellWithIdentifier:, nil. , , tableView, indexPath, if (cell == nil); .

+5

, , .

.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
    // You got a problem with all these ifs and elses. 2 things are happening. 
    if (indexPath.row == 0) <----Is called
    {
        [self performSegueWithIdentifier:@"showFlashFireSet" sender:self];

    }
    if (indexPath.row == 1) <---also called
    {
        [self performSegueWithIdentifier:@"showXYBaseSet" sender:self];
    }
    else <--- this is also called. 
    {
        [self performSegueWithIdentifier:@"showLegendarySet" sender:self];
    } */



    if (indexPath.row == 0)
{
    [self performSegueWithIdentifier:@"showFlashFireSet" sender:self];
     break;
}
else if (indexPath.row == 1) // notice the else on this line
{
    [self performSegueWithIdentifier:@"showXYBaseSet" sender:self];
    break;
}
else
{
    [self performSegueWithIdentifier:@"showLegendarySet" sender:self];
     break;
}

}
+1

Source: https://habr.com/ru/post/1547647/


All Articles