- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import UIKit
class MasterTableViewController: UITableViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, UISearchResultsUpdating {
var searchNotes: PFObject = PFObject()
var filteredNotes = [String]()
var resultSearchController = UISearchController()
var searchActive: Bool = false
// creating array for holding ojects
var noteObjects: NSMutableArray! = NSMutableArray()
var v = 0
override func viewDidLoad() {
super.viewDidLoad()
self.resultSearchController = UISearchController(searchResultsController: nil)
self.resultSearchController.searchResultsUpdater = self
self.resultSearchController.dimsBackgroundDuringPresentation = false
self.resultSearchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = self.resultSearchController.searchBar
self.tableView.reloadData()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if v == 0 {
self.fetchAllObjectsFromLocalDataStore()
//self.fetchAllObjects()
}
}
// fetching data from local datastore and from parse
func fetchAllObjectsFromLocalDataStore(){
let query: PFQuery = PFQuery(className: "Sinhgad")
query.orderByDescending("createdAt")
query.fromLocalDatastore()
query.findObjectsInBackgroundWithBlock { ( objects, error) -> Void in
if (error == nil) {
let temp: NSArray = objects as NSArray!
self.noteObjects = temp.mutableCopy() as! NSMutableArray
self.tableView.reloadData()
}else {
print(error!.userInfo)
}
}
}
func fetchAllObjects(){
let query: PFQuery = PFQuery(className: "Sinhgad")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if (error == nil) {
PFObject.pinAllInBackground(objects, block: nil )
self.fetchAllObjectsFromLocalDataStore()
// self.tableView.reloadData()
} else {
print(error?.userInfo)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if self.resultSearchController.active
{
return self.filteredNotes.count
}else{
return self.noteObjects.count
}}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! MasterTableViewCell
if self.resultSearchController.active
{
cell.textLabel?.text = self.filteredNotes[indexPath.row]
searchNotes = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
cell.MasterTitleLabel?.text = searchNotes["Title"] as? String
cell.MasterTextLabel.text = searchNotes["Fstory"] as? String
cell.MasterTimeLabel.text = searchNotes["Time"] as? String
cell.MasterLocationLabel.text = searchNotes["Location"] as? String
return cell
} else {
let object : PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
cell.MasterTitleLabel?.text = object["Title"] as? String
cell.MasterTextLabel.text = object["Fstory"] as? String
cell.MasterTimeLabel.text = object["Time"] as? String
cell.MasterLocationLabel.text = object["Location"] as? String
print(searchNotes)
return cell
}}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if self.resultSearchController.active
{
self.performSegueWithIdentifier("openStory", sender: self)
} else {
self.performSegueWithIdentifier("openStory", sender: self)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let upcoming: AddNoteTableViewController = segue.destinationViewController as! AddNoteTableViewController
if (segue.identifier == "openStory"){
let indexPath = self.tableView.indexPathForSelectedRow!
let object: PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
upcoming.object = object
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
@IBAction func btnReload(sender: AnyObject) {
fetchAllObjects()
print(searchNotes)
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete ){
if self.resultSearchController.active
{
}else{
let object : PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject
// the below for deleting the selected cell's object from server's database
// object.deleteInBackground()
//the below for deleting the selected cell's object from localstorage
object.unpinInBackground()
self.noteObjects.removeObjectAtIndex(indexPath.row)
}
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
self.filteredNotes.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
let array = (self.noteObjects as NSArray).filteredArrayUsingPredicate(searchPredicate)
self.filteredNotes = array as! [String]
self.tableView.reloadData()
print(searchNotes)
}
}
我正在尝试实现 uisearchbar,但我不知道在尝试运行应用程序时出现错误,如果有人知道出了什么问题,请告诉我
出现错误:
2015-12-04 00:41:31.915 Notes[1950:228026] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can only call -[PFObject init] on subclasses conforming to PFSubclassing.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106ff8e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108d37deb objc_exception_throw + 48
2 CoreFoundation 0x0000000106ff8d9d +[NSException raise:format:] + 205
3 Notes 0x00000001059abac6 -[PFObject init] + 146
4 Notes 0x000000010597c5b0 _TTOFCSo8PFObjectcfMS_FT_S_ + 16
5 Notes 0x000000010597c2e7 _TFCSo8PFObjectCfMS_FT_S_ + 71
6 Notes 0x000000010597b2a5 _TFC5Notes25MasterTableViewControllercfMS0_FT5coderCSo7NSCoder_GSqS0__ + 37
7 Notes 0x000000010597b3fd _TToFC5Notes25MasterTableViewControllercfMS0_FT5coderCSo7NSCoder_GSqS0__ + 45
8 UIKit 0x0000000107bd417f -[UIClassSwapper initWithCoder:] + 241
9 UIKit 0x0000000107da67ba UINibDecoderDecodeObjectForValue + 705
10 UIKit 0x0000000107da64f0 -[UINibDecoder decodeObjectForKey:] + 278
11 UIKit 0x0000000107bd3e55 -[UIRuntimeConnection initWithCoder:] + 180
12 UIKit 0x0000000107bd4589 -[UIRuntimeEventConnection initWithCoder:] + 60
13 UIKit 0x0000000107da67ba UINibDecoderDecodeObjectForValue + 705
14 UIKit 0x0000000107da697b UINibDecoderDecodeObjectForValue + 1154
15 UIKit 0x0000000107da64f0 -[UINibDecoder decodeObjectForKey:] + 278
16 UIKit 0x0000000107bd3067 -[UINib instantiateWithOwner:options:] + 1255
17 UIKit 0x0000000107f39a04 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
18 UIKit 0x0000000107f3e6c8 -[UIStoryboardSegueTemplate instantiateOrFindDestinationViewControllerWithSender:] + 90
19 UIKit 0x0000000107f3e925 -[UIStoryboardSegueTemplate _perform:] + 52
20 UIKit 0x0000000107f3ec07 -[UIStoryboardSegueTemplate perform:] + 156
21 UIKit 0x00000001078198c8 -[UIApplication sendAction:to:from:forEvent:] + 92
22 UIKit 0x0000000107988328 -[UIControl sendAction:to:forEvent:] + 67
23 UIKit 0x00000001079885f4 -[UIControl _sendActionsForEvents:withEvent:] + 311
24 UIKit 0x0000000107987724 -[UIControl touchesEnded:withEvent:] + 601
25 UIKit 0x0000000107888bcf -[UIWindow _sendTouchesForEvent:] + 835
26 UIKit 0x0000000107889904 -[UIWindow sendEvent:] + 865
27 UIKit 0x000000010783829a -[UIApplication sendEvent:] + 263
28 UIKit 0x0000000117611ff9 -[UIApplicationAccessibility sendEvent:] + 77
29 UIKit 0x00000001078124cb _UIApplicationHandleEventQueue + 6844
30 CoreFoundation 0x0000000106f24a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
31 CoreFoundation 0x0000000106f1a8d7 __CFRunLoopDoSources0 + 423
32 CoreFoundation 0x0000000106f19e13 __CFRunLoopRun + 867
33 CoreFoundation 0x0000000106f19828 CFRunLoopRunSpecific + 488
34 GraphicsServices 0x000000010ab6aad2 GSEventRunModal + 161
35 UIKit 0x0000000107817d44 UIApplicationMain + 171
36 Notes 0x0000000105971afd main + 109
37 libdyld.dylib 0x0000000109ebd92d start + 1
38 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我正在尝试实现 uisearchbar,但我不知道在尝试运行应用程序时出现错误,如果有人知道出了什么问题,请告诉我
最佳答案
此错误由 var searchNotes: PFObject = PFObject()
行引起,这意味着您无法直接实例化对象。根据Developers Guide您需要使用 Parse Cloud 中的实际名称实例化您的对象。像这样:
var searchNotes = PFObject(className:"YourObjectName")
更新。
阅读您的代码,我假设您想使用PFObject
数组而不是单个对象。
更新。
我打赌你下一个错误是由这两行引起的:
let array = (self.noteObjects as NSArray).filteredArrayUsingPredicate(searchPredicate)
self.filteredNotes = array as! [String]
因为您尝试将谓词用于 String
和 PFObjects
。但是这个问题与原题无关。
好的。我猜你需要这个:
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
var array = (self.noteObjects as! [PFObject]).map { (obj) -> String
obj["Title"]
}
array = (array as NSArray).filteredArrayUsingPredicate(searchPredicate)
关于ios - 为 PFobjects 实现 UISearchController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34074406/
[X-Post from parse.com] Person是 PFObject 的子类 . Address也是 PFObject 的子类 . Address有一个 @property类型 Perso
我在 Parse(在 iOS 上)中的当前用户返回正常,它拥有的属性之一是指向 PFObject“A”的指针。因此,当我获得当前用户时,我可以在当前用户中看到指向“A”的有效指针。 我不知道如何从那里
我正在尝试创建一个可以删除以下项目的函数: var array = [23,36,12,45,52,63] removeItem(12,array) result : array = [23,36,4
所以我正在设置这个应用程序,用户可以看到他们的位置,也可以看到其他人的位置。对于脚本,我正在关注这个问题。 how to retrive location from a PFGeopoint - (P
我正在使用 PFObject 子类化,例如: @interface CarObject : PFObject @property (nonatomic, strong) BrandObject *b
我只是想知道最简单/建议的方法是删除 PFObject 及其相关的所有内容。例如,在照片分享应用中,如果上传者想删除他/她发布的照片,您如何同时删除与该照片相关的所有“赞”和评论? 现在,我正在使
假设我有一组“myObject”类的PFObjects(本质上是字典)。此类的对象包含字典键“myDictionary”。反过来,“myDictionary”有一个键“myKey”,我想访问它并搜索与
我在 Xcode 中出现一个错误,提示“Downcast from '[PFObject]?'” '[PFObject]' 只解包可选值;您是要使用“!”吗? var iDArray = [S
Xcode 6.3.1:错误:无法将“PFObject”类型的值分配给“PFObject!”的值 试图理解更严格的 Swift '!'和 '?'要求,因为我认为这是错误的主要原因。 问题出在下面的代码
我正在将解析查询保存到数组中,但在 if letobjects=objectsas? 上出现以下错误? [PF对象] 并且出现以下错误:从“[PFObject]?”向下转型?到“[PFObject]”
我有一个名为 FriendRelation 的 Parse 类。这个类(class)有两个用户,一个是 friend ,另一个是用户。 我想获取用户的所有 friend 发布的所有消息。我尝试使用以下
然后我尝试将键从 PFObject 转换为字符串,但出现错误。我在 Parses 网站上找不到任何内容。请帮忙 var findProgram = PFQuery(className: "Progra
在我的应用程序中,当我尝试注册时,PFObjects 未保存在后台(emailLabel、FirstNameLabel、LastNameLabel、PasswordLabel。知道为什么吗 这是一个代
我已将 userIds 保存在解析为 String 的列中,并且我想将其转换为 PFObject 。我怎样才能快速做到这一点?我试图按如下方式检索 userId: followedUserQuery.
我有一个计时器,可以将当前日期倒计时到我在 Parse 中设置的日期(类名:“Date”)。现在,它使用我设置的 ObjectId 检索该数据。我想将其设置为使用“updatedAt”列中的日期来调用
我已经查看了所有内容,人们说使用 whereKey: equalTo: 可以在数组中工作,但由于某种原因它不适合我。我试图让用户搜索标签,并且包含该标签的所有帖子都会出现。当我删除 whereKey:
我有一个PFObject,Account,其中包含一个User数组,它们是PFUsers的子类。然后,User 有一个 NSDictonary 属性 allowableApps,它是一个 NSDict
我使用 Parse 作为我的后端,我试图让两个子类映射到同一个表。 在我的模型中,我有一个抽象的 Post 类,它符合 PFSubclassing 协议(protocol)并包含几个属性和方法。在我的
我想将来自 Parse 查询的 PFObjects 保存在我的类称为 listdata 的 NSMutableArray 中。我稍后会使用 listdata 数组。当我跟踪我的代码时,它会为找到的每个
我在使用 key 成功检索 PFObject 时遇到问题。对象最后为零: var object = PFObject(className:"Topic") var query = PF
我是一名优秀的程序员,十分优秀!