用于nil的未定义方法`pushViewController':NilClass(NoMethodError)

时间:2014-07-30 18:32:03

标签: ios rubymotion pushviewcontroller

我构建了一个rubymotion应用程序,目前正在等待Apple审核。我的注意力集中在我的应用程序上,并注意到在审核过程中发生了错误。但是,我无法在iPhone 4S上复制此错误。

错误发生在:iPad Air使用7.1.2和Wifi(不是蜂窝数据)。

错误是:undefined method pushViewController for nil:NilClass (NoMethodError)

似乎发生在我的代码的这一部分:

  def locationManager(manager, didUpdateToLocation:newLocation, fromLocation:oldLocation)
    @my_location_manager.stopUpdatingLocation
    #error occurs on the line below
    self.navigationController.pushViewController(MyController.alloc.initWithData(item, newLocation.coordinate.latitude, newLocation.coordinate.longitude), animated:true)
  end

整个班级看起来像这样:

class SomeController < UITableViewController
   def locationManager(manager, didUpdateToLocation:newLocation, fromLocation:oldLocation)
      @my_location_manager.stopUpdatingLocation
      #error occurs on the line below
      self.navigationController.pushViewController(MyController.alloc.initWithData(item, newLocation.coordinate.latitude, newLocation.coordinate.longitude), animated:true)
   end

  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
      initAFNetworkingClient
      @name = self.data[indexPath.row][:name]  
      if @name == "FooBar"

        if (CLLocationManager.locationServicesEnabled)
          @my_location_manager = CLLocationManager.alloc.init
          @my_location_manager.delegate = self

          @my_location_manager.purpose = "To provide functionality based on user's current location"
          @my_location_manager.startUpdatingLocation
        else
          p "Location services are not enabled."
        end
      elsif @name == "Bar"
        self.navigationController.pushViewController(OtherController.alloc.init, animated: true)
      end    
end

有人可以解释为什么我的应用会出现此错误吗?或者我如何在设备上复制问题?或者如果我在这里做错了什么的话。

0 个答案:

没有答案