您好,我正在学习 Swift,我正在尝试将 Parse 实现到我的应用程序中。所以我有一个 MapView,它有一些注释。这些注释是从存储在 Parse 数据库中的坐标绘制的。 Parse 中的每个坐标元组都有其他详细信息,如 FirstName LastName 等。现在,一旦用户单击 mapView 中存在的 DETAILS 按钮。它将用户带到一个 TableView Controller ,用户可以在其中看到与在 mapView 中可见的坐标有关的所有详细信息。到现在为止一切正常。所以如果我在 map View 中有 4 个注释。然后通过单击 DETAILS,我被重定向到 TableView Controller ,在那里我可以看到与 mapView 中存在的所有坐标/注释相关的详细信息。现在我想要一个用户可以点击 TableView Controller 单元格的功能,我可以将数据传递给与该特定单元格相关的另一个 View 。因此,如果在 TableView Controller 中,用户单击属于 map View 上显示的注释之一的第 4 个单元格。我希望将第 4 个单元格详细信息传递给另一个 View Controller 。
map View (带有多个注释)-> tableview Controller (带有多个单元格)-> View Controller (与用户点击的单元格相关)。
问题:只要我单击 TableView Controller 中的任何单元格,以便我可以在另一个 View Controller 中看到该单元格的详细信息,我的应用程序就会崩溃,我会看到错误
2015-11-30 21:38:42.998 LifeLine[53788:6661072] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can only call -[PFObject init] on subclasses conforming to PFSubclassing.'
我在 TableView Controller 中放置了断点 AT PREPAREFORSEGUE METHOD。但即使在 prepareforsegue 方法断点命中之前,我的应用程序已经崩溃了。所以崩溃发生在我点击单元格和在 prepareforsegue 上设置断点之间。
我的 map View Controller :
import UIKit
import MapKit
import MessageUI
class MultipleAnnotationViewController: UIViewController, MKMapViewDelegate, MFMailComposeViewControllerDelegate
{
var arrayOfPFObject: [PFObject] = [PFObject]()
var lat_ :Double = 0
var long_ :Double = 0
@IBOutlet weak var dispAnnotation: MKMapView!
let currentUser = PFUser.currentUser()
var pinAnnotationView:MKPinAnnotationView!
override func viewDidLoad()
{
super.viewDidLoad()
dispAnnotation.delegate = self
for coordinateItem in arrayOfPFObject
{
let pointAnnotation = MKPointAnnotation()
self.lat_ = coordinateItem["Latitude"] as! Double
self.long_ = coordinateItem["Longitude"] as! Double
pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: self.lat_, longitude: self.long_)
dispAnnotation.addAnnotation(pointAnnotation)
pointAnnotation.title = String(coordinateItem["FirstName"]) + " " + String(coordinateItem["LastName"])
let miles = 10.0
let scalingFactor = abs(( cos ( 2*M_PI*pointAnnotation.coordinate.latitude/360.0 ) ) )
var span = MKCoordinateSpan(latitudeDelta: 0, longitudeDelta: 0)
span.latitudeDelta = miles/69.0
span.longitudeDelta = miles/(scalingFactor * 69.0)
let region = MKCoordinateRegionMake(pointAnnotation.coordinate, span)
[ self.dispAnnotation.setRegion(region, animated: true)]
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "TableView"
{
let controller = segue.destinationViewController as! TableViewController
controller.arrayOfPFObject = arrayOfPFObject
}
if segue.identifier == "TableView2"
{
let controller = segue.destinationViewController as! ChecklistViewController
controller.arrayOfPFObject = arrayOfPFObject
}
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
{
guard !(annotation is MKUserLocation)
else
{
return nil }
let identifier = "com.domain.app.something"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? MKPinAnnotationView
if annotationView == nil
{
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.pinTintColor = UIColor.redColor()
annotationView?.canShowCallout = true
}
else
{
annotationView?.annotation = annotation
}
return annotationView
}
}
我的 TableViewController:
import UIKit
class ChecklistViewController: UITableViewController
{
override func viewDidLoad() {
super.viewDidLoad()
}
var arrayOfPFObject: [PFObject] = [PFObject]()
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return arrayOfPFObject.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier(
"ChecklistItem", forIndexPath: indexPath)
let label = cell.viewWithTag(1000) as! UILabel
print(arrayOfPFObject.count)
print(indexPath.row)
let coordinateItem = arrayOfPFObject[indexPath.row]
label.text = String(coordinateItem["Address"])
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "call"
{
let controller = segue.destinationViewController as! CallEmailViewController
if let indexPath = tableView.indexPathForCell( sender as! UITableViewCell)
{
controller.itemToEdit = arrayOfPFObject[indexPath.row]
}
}
}
}
我的 View Controller ,我想在其中显示所点击单元格的详细信息。
import UIKit
import CoreLocation
import MapKit
class CallEmailViewController: UITableViewController
{
var itemToEdit: PFObject = PFObject()
override func viewDidLoad()
{
super.viewDidLoad()
mail() //print(arrayOfPFObject.count)
}
func mail()
{
print("")
}
}
下面是表格 View 图像。只要我点击任何表格 View ,我就会收到错误消息。
最佳答案
将 var itemToEdit: PFObject = PFObject() 更改为
var itemToEdit: PFObject?
关于swift - 崩溃 : Can only call -[PFObject init] on subclasses conforming to PFSubclassing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34012011/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,
任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb
我使用vim编辑ruby文件,但是当我输入“.”时它崩溃了。我发现它是由AutoComplPop插件引起的。我该怎么办? 最佳答案 我找到了一种使用autocomplpop和filetype=ruby来防止vim崩溃的方法。将以下行放入您的.vimrcletg:acp_behaviorRubyOmniMethodLength=-1这将防止在您键入“.”时触发autocomplpop。(期间)这不是解决办法。(我不是vim插件程序员)祝你好运! 关于ruby-vim使用AutoComp
您好,我正在尝试通过阅读TheRubyProgrammingLanguage一书来提高我的Ruby知识。阅读Codersatwork我看到很多受访者建议深入研究项目源代码学习最佳实践注意不良习惯当然还有做事的新灵感。我决定选择一个尽可能独立的项目。我的选择是Sinatra,因为它有1000LOC。这是一个学习的好项目吗?您是否建议另一种更简单的方法(即更少的LOC)?我以前曾尝试过看轨道机械,但我被它吓坏了。 最佳答案 我不太喜欢Ruby(虽然我玩过一点Sinatra),但我想说的是,CodersatWork建议应该被理解为“不仅从
我在Rails5项目的app/services文件夹下有多个加载/需要类的问题,我开始放弃这个问题。首先要明确的是,services/是我在整个项目中使用的简单PORO类,用于从Controller、模型等中抽象出大部分业务逻辑。树看起来像这样app/services/my_service/base.rbfunny_name.rbmy_service.rbmodels/funny_name.rb失败#1首先,当我尝试使用MyService.const_get('FunnyName')时,它从我的模型目录中获取了FunnyName。当我直接执行MyService::FunnyName时,
我正在从Ruby2.3.1升级到Ruby2.4.1,这样做之后,Unicorn似乎与新版本不兼容。我收到以下错误。我正在使用Unicorn5.1.0并尝试过Unicorn5.3.1无济于事。我是否需要使用不同的库而不是XCode工具进行编译?我在使用foremanstart和Procfile启动服务器后立即收到错误:webpack:bin/webpack-dev-servergulp:gulpredis:./scripts/start_redis_server.shsidekiq:bundleexecsidekiq-Cconfig/sidekiq.ymlannotations_serv
这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭10年前。我在部署这个应用程序时从未遇到过问题,但我刚刚推送,现在我遇到了这个奇怪的错误,它在堆栈中足够深,甚至没有被发送到Airbrake。我觉得这可能是Heroku的问题,可能与https://status.heroku.com/incidents/450有关。?你怎么看?2012-10-14T08:40:31+00:00heroku[web.1]:State
我使用Gemfile中的新gem重新部署我的heroku应用程序,它在启动时崩溃了/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in`require':libruby.so.1.9:cannotopensharedobjectfile:Nosuchfileordirectory-/app/vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.so(LoadError)无论我部