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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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 如何在单元测试中打开UIImageView_Ios_Iphone_Swift - Fatal编程技术网

Ios 如何在单元测试中打开UIImageView

Ios 如何在单元测试中打开UIImageView,ios,iphone,swift,Ios,Iphone,Swift,我有一个UIImageView,它位于导航栏的左侧。我如何在XCTestCase中点击imageView?根据您的评论,假设您有一个带有UIImage的UIBarButtonItem,并且您已经定义了一些@iAction,当您在UIBarButtonItem中单击时,您可以在UIBarButtonItem中模拟点击,如下所示: @IBOutlet weak var barButtonItem: UIBarButtonItem! override func viewDidLoad() {

我有一个UIImageView,它位于导航栏的左侧。我如何在XCTestCase中点击imageView?

根据您的评论,假设您有一个带有
UIImage
UIBarButtonItem
,并且您已经定义了一些
@iAction
,当您在
UIBarButtonItem
中单击时,您可以在
UIBarButtonItem
中模拟点击,如下所示:

@IBOutlet weak var barButtonItem: UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    // Send the the action to invoke the target specified when you make your @IBAction or define a target manually.
    UIApplication.sharedApplication().sendAction(barButtonItem.action, to: barButtonItem.target, from: nil, forEvent: nil)
}  

// @IBAction defined using Interface Builder
@IBAction func buttonTapped(sender: AnyObject) {
    print("Tapped")
}
在上述代码中,当加载
UIViewController
时,您将在控制台中看到输出
“点击”
。初始化要测试的
UIViewController
时,可以将相同的逻辑转换为单元测试

定义了
uiBarButtonim
后,无需为其内部的
UIImage
定义
uiAppgestureRecognitizer
,即可知道何时点击它


我希望这对你有所帮助。

根据你的评论,假设你有一个带有
UIImage
UIBarButtonItem
,并且你定义了一些
@iAction
,当你点击
UIBarButtonItem
时,你可以在
UIBarButtonItem
中模拟一个点击,如下:

@IBOutlet weak var barButtonItem: UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    // Send the the action to invoke the target specified when you make your @IBAction or define a target manually.
    UIApplication.sharedApplication().sendAction(barButtonItem.action, to: barButtonItem.target, from: nil, forEvent: nil)
}  

// @IBAction defined using Interface Builder
@IBAction func buttonTapped(sender: AnyObject) {
    print("Tapped")
}
在上述代码中,当加载
UIViewController
时,您将在控制台中看到输出
“点击”
。初始化要测试的
UIViewController
时,可以将相同的逻辑转换为单元测试

定义了
uiBarButtonim
后,无需为其内部的
UIImage
定义
uiAppgestureRecognitizer
,即可知道何时点击它


我希望这能对您有所帮助。

导航栏左侧的
UIImageView
是什么意思?这是一个带有图像的
uibarbuttoneim
?没错!它还打开了手势识别器,你说导航栏左侧的
UIImageView
是什么意思?这是一个带有图像的
uibarbuttoneim
?没错!而且它已经开启了手势识别器