草庐IT

ios - 获取 "nested push animation can result in corrupted navigation bar"

coder 2023-09-27 原文

我完全卡住了。我一直在四处寻找答案,似乎每个人对每个“嵌套推送动画可能导致导航栏损坏”错误都有不同的问题。

请记住,我正在尝试自学如何为 iOS 7 编码。因此,如果我的某些编码方法不理想,我很抱歉,请提供反馈。无论如何,我正在创建一个 Pokemon Trading Card Game Pokedex 应用程序,它显示最新系列的卡片。除了我在主屏幕上选择第一个表格单元格 (XY Flash Fire) 之外,一切都运行良好。它将显示正确的表格数据,但导航栏标题不正确。当我选择一行时,它也不会转到 PokedexDetailViewController。

同样,主屏幕上的所有其他表格单元格都可以正常工作。我还尝试了人们在此处和 github 上发布的其他修复程序和类,但没有一个对我有用。我还重新创建了整个 FlashFireViewController,但仍然有同样的问题。确保所有代码与其他工作 View Controller 几乎相同。还验证了 segues 来自 Set View Controller,反对单元格。然而,一旦它在 Flash Fire View Controller 中,segues 就从单元格开始。

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

  1. 我的 Storyboard是如何设置的。
  2. 应用启动后的主屏幕。
  3. 当我选择第二个单元格 (XY) 时。
  4. 当我选择 Mega Venusaur EX 时。
  5. **错误。当我选择第一个单元格(XY Flash Fire)时。它显示了正确的表格数据,但不是正确的导航标题。
  6. 当我选择 Butterfree 或任何其他 pokemon 时,没有任何反应,导航标题也消失了。此外,一旦我反击,应用程序就会崩溃并停止。

这是主屏幕类 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.mtableView:didSelectRowAtIndexPath 中。

您有一个 if 语句,后跟一个 if else 语句。当 indexPath.row == 0 第一个 if 为真时,执行 [self performSegueWithIdentifier:@"showFlashFireSet"sender:self]。但是随后代码继续执行到 if else block 中。那里有两个单独的执行 block 。由于 indexPath.row 仍然是 0,我们将进入 else block ,并执行另一个 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。但是您在发布的代码中两次调用该方法,并且两次都在具有可用的 indexPathtableView 数据源方法中调用,因此请利用它并删除那些 if (cell == nil) 检查;这是解放。

关于ios - 获取 "nested push animation can result in corrupted navigation bar",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24640835/

有关ios - 获取 "nested push animation can result in corrupted navigation bar"的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  5. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  6. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  7. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  8. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  9. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  10. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

随机推荐