为什么ViewController不声明当它包含一个NavigationController时当推送一个segue



我只是想有一个segue传递一些东西给我的SecondViewController但它'不存在'在我的代码。我得到一个错误"使用身份不明的标识符SecondViewController",但我已经导入了它相应的。h文件。
我已经尝试了一些不同的组合,试图显式声明它,但没有工作。
做这件事的正确方法是什么?我错过了什么?
我的SecondViewController有一个NavigationControllerEmbedded,所以从FirstViewController到SecondViewController的segue对于一个相对简单的过程来说似乎非常困难。

代码:
FirstViewController.h

(Should there be something here?)


FirstViewController.m

#import "FirstViewController.h"
#import "SecondViewController.h" 
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"123"]) {
        UINavigationController *navController = [segue destinationViewController];
        SecondViewController *BVC = (SecondViewController *)([navController viewControllers][0]); 

我在上面一行得到错误。

BVC.ATitle = @"SomeText"
BVC.AImg = [UIImage imageNamed:@"SomePicture.jpg"];
    }
}


SecondViewController.h

@property (strong, nonatomic) IBOutlet UILabel *ALabel;
@property (strong, nonatomic) IBOutlet UIImageView *AImageView;
@property (strong, nonatomic) UIImage *AImg;
@property (strong, nonatomic) NSString *ATitle;


SecondViewController.m

#import "FirstViewController.h"
#import "SecondViewController.h" 
@implementation ButtonViewController
@synthesize ALabel;
@synthesize AImageView;
- (void)viewDidLoad
{
    self.ALabel.text = self.ATitle;
    self.AImageView.image = self.AImg;
}

编辑:但是我错过了公然错过了在我的代码中的任何地方的secondViewController的声明,否则为什么当我开始尝试和键入它时,它甚至不会出现在提示符中。即使我在没有NavController的情况下尝试它,它仍然会给出未识别标识符错误。

navigationController.topViewController代替navigationController.viewControllers[0]

尝试从Xcode中删除第二个视图控制器文件(不将它们移动到Trash中),然后重新添加它们。此外,在再次编译之前清理项目。

代码的另一个问题是,您没有遵循在camelCase中使用以小写字母开头的变量名的惯例。虽然这对编译没有影响,但它确实使代码的可读性降低。

最新更新