iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 获取“嵌套推送动画可能导致导航栏损坏”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我完全卡住了.我一直在寻找答案,似乎每个人都有一个不同的问题,每个“嵌套推送动画可能会导致导航栏损坏”错误. 请记住,我正在尝试自学如何为iOS 7编写代码.因此,如果我的某些编码方法不理想,我很抱歉,请提供反馈.无论如何,我正在创建一个口袋妖怪交易卡游戏Pokedex应用程序,显示最新集的卡.除了在主屏幕上选择第一个表格单元格(XY Flash FirE)时,一切都完美无缺.它将显示正确的表格数
@H_607_18@ 我完全卡住了.我一直在寻找答案,似乎每个人都有一个不同的问题,每个“嵌套推送动画可能会导致导航栏损坏”错误.

请记住,我正在尝试自学如何为iOS 7编写代码.因此,如果我的某些编码方法不理想,我很抱歉,请提供反馈.无论如何,我正在创建一个口袋妖怪交易卡游戏Pokedex应用程序,显示最新集的卡.除了在主屏幕上选择第一个表格单元格(XY Flash FirE)时,一切都完美无缺.它将显示正确的表格数据,但导航栏标题不正确.当我选择一行时,它也不会去PokedexDetailViewController.

同样,主屏幕中的所有其他表格单元格都没有问题.我还尝试了其他人在这里发布的修补程序和类以及github,但没有一个我有效.我还重新创建了整个FlashFireViewController并仍然遇到了同样的问题.确保所有代码与其他工作视图控制器完全相同.还验证了segue来自Set View Controller,与细胞相对.但是,一旦它在Flash Fire View Controller中,segue就会从单元格中产生.

不能发布照片,所以这里是我的屏幕截图的专辑链接http://imgur.com/a/Dq9py

>我的故事板是如何设置的.
>应用程序启动后的主屏幕.
>当我选择第二个单元格(XY)时.
>当我选择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:

解决方法

您的问题很可能出现在TCGSetViewController.m中的tableView:didSELEctRowATindexPath中.

你有一个if语句后跟一个if else语句.当indexPath.row == 0时,第一个if为true,执行[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)check;这是解放.

大佬总结

以上是大佬教程为你收集整理的ios – 获取“嵌套推送动画可能导致导航栏损坏”全部内容,希望文章能够帮你解决ios – 获取“嵌套推送动画可能导致导航栏损坏”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。