Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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
Javascript 可以用我自己的方法扩展UIAEElementArray吗?_Javascript_Iphone_Ios_Ui Automation_Ios Ui Automation - Fatal编程技术网

Javascript 可以用我自己的方法扩展UIAEElementArray吗?

Javascript 可以用我自己的方法扩展UIAEElementArray吗?,javascript,iphone,ios,ui-automation,ios-ui-automation,Javascript,Iphone,Ios,Ui Automation,Ios Ui Automation,我做了以下工作: function extend(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination; }; extend( UIAElementArray.prototype, { each: function(f) { for (i = 0;

我做了以下工作:

function extend(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
};

extend( UIAElementArray.prototype, 
{
       each: function(f) 
       {
        for (i = 0; i < this.length; i++) 
        {
          f(i, this[i]);
        }
       },

       findFirst: function(f) 
       {
         for (i = 0; i < this.length; i++) 
         {
           if (f(this[i])) return this[i];
         }
         return null;
       },

       findLast: function(f) 
       {
         for (i = this.length - 1; i >= 0; i--) 
         {
          if (f(this[i])) return this[i];
         }
         return null;
       }
} );

但是,当我尝试使用从mainWindow.tableViews[0].cells获取的对象上的每个函数时,[object UIAElementNil]不是一个函数。为什么我添加到UIAElementArray.prototype的每个属性都设置为[object UIAElementNil]?这种情况发生了,当我在真实设备上运行UIAutomation测试时,它会在模拟器上运行,令人惊讶。

在Objective-C中,您可以扩展任何类,并使用类别将自定义方法添加到这些类中。

当然,您可以扩展UIAEElementArray,而不是Objective-C。tuneup.js使用与上面使用的方法相同的方法,效果很好,我也使用了相同的方法来扩展UIAElementArray。我无法解释为什么您的脚本报告您正在使用UIAElementNil,但您对UIAElementArray的扩展似乎是正确的


这里真正的问题可能是为什么这在模拟器上工作,而不是在设备上?。设备是否运行iOS 5或更高版本?我见过iOS 4.3设备在大部分情况下都可以正常工作,脚本是用5录制或编写的,但我也见过更复杂的脚本在4.3设备上变得不稳定。

这个答案完全没有抓住要点。问题是基于JavaScript的UIAutomation。与ObjectiveC没有任何关联。