在UIViewController上使用pushViewController不会在堆栈上推送新的控制器

时间:2014-10-06 19:57:13

标签: ios objective-c uiviewcontroller tdd

我正在编写测试以验证在进行某个操作时某个类型的新视图控制器是否被推送到导航控制器的堆栈上。但是,我发现调用pushViewController不会导致我的UIViewController视图控制器列表被更新,而前一个视图控制器也不会被新推送的控制器。

这是我的测试类的缩写版本:

#import "RRViewController.h"
#import "RestroomDetailsViewController.h"

@implementation RRViewControllerTests
{
    RRViewController *viewController;
    ...
    UINavigationController *navigationController;
}

- (void)setUp
{
    [super setUp];

    viewController = [[RRViewController alloc] init];
    ...
    navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
}

...

- (void)testSelectingRestroomPushesNewViewController
{
    [viewController userDidSelectRestroom];

    UIViewController *currentTopViewController = navigationController.topViewController;

    XCTAssertFalse([currentTopViewController isEqual:viewController], @"New view controller should be pushed onto Navigation Controller stack.");

    XCTAssertTrue([currentTopViewController isKindOfClass:[RestroomDetailsViewController class]], @"New view Controller should be an RestroomDetailsViewController.");
}

这是RRViewController类,其中userDidSelectRestroomn方法调用了viewController

#import "RestroomDetailsViewController"

...

- (void)userDidSelectRestroom
{
    RestroomDetailsViewController *nextViewController = [[RestroomDetailsViewController alloc] init];

    [[self navigationController] pushViewController:nextViewController animated:YES];
}

问题是我的两个测试都失败了。在navigationController.viewControllers被调用后,查看RRViewControllerTests测试类中的userDidSelectRestroom会显示:

<__NSArrayI 0x7ffaf9d37020>(
    <RRViewController: 0x7ffaf9eba420>
)

即。只是原始的根RRViewController

有关为什么新RestroomDetailsViewController没有被推到navigationController堆叠的任何想法?

0 个答案:

没有答案