Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UIViewController上使用pushViewController不会将新控制器推送到堆栈上_Ios_Objective C_Uiviewcontroller_Tdd - Fatal编程技术网

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

Ios 在UIViewController上使用pushViewController不会将新控制器推送到堆栈上,ios,objective-c,uiviewcontroller,tdd,Ios,Objective C,Uiviewcontroller,Tdd,我正在编写测试,以验证在执行某个操作时,是否将某个类型的新视图控制器推送到导航控制器的堆栈上。但是,我发现调用pushViewController不会导致更新我的UIViewControllers视图控制器列表,也不会导致最上面的列表成为新推送的控制器 以下是我的测试类的缩写版本: #import "RRViewController.h" #import "RestroomDetailsViewController.h" @implementation RRViewControllerTest

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

以下是我的测试类的缩写版本:

#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
类,它在
viewController
上调用了
userDidSelectRestroomn
方法:

#import "RestroomDetailsViewController"

...

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

    [[self navigationController] pushViewController:nextViewController animated:YES];
}
问题是我的两项测试都失败了。查看
RRViewControllerTests
测试类中的
navigationController.viewControllers
,调用
userDidSelectRestroom
后显示:

<__NSArrayI 0x7ffaf9d37020>(
    <RRViewController: 0x7ffaf9eba420>
)
(
)
i、 e.只需原始根
RRViewController


关于为什么新的
RestroomDetailsViewController
没有被推到
navigationController
的堆栈上有什么想法吗?

您是否尝试过在没有动画的情况下测试它?在动画完成之前,不能将其添加到堆栈中。只需尝试-测试通过!