【发布时间】:2014-10-21 16:28:40
【问题描述】:
我在 UIControllerView 中有一个按钮,用于通过 Parse.com 后端跟踪特定用户。
我想要这种行为:
-> 用户不是朋友,按钮状态 = 未选中,在 Parse.com 中执行以下操作 => 将按钮状态更改为选中
-> 用户是朋友,按钮状态 = 选中,在 parse.com 中执行取消关注操作 => 将按钮状态更改为未选中
我的问题是:
如果按钮被选中(因为用户已经是朋友)=> 一切正常
如果按钮没有被选中(因为用户不是朋友)=>
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Sliked.FriendsProfileViewControler followButton:]: unrecognized selector sent to instance 0x7f7f7ad63370'
*** First throw call stack:
(
0 CoreFoundation 0x000000010aabe3f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c5ecbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010aac550d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010aa1d7fc ___forwarding___ + 988
4 CoreFoundation 0x000000010aa1d398 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010b3499ee -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010b44fbd0 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010b44ef9f -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010b38f3b8 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x000000010b38fce3 -[UIWindow sendEvent:] + 683
10 UIKit 0x000000010b35cae1 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010b369bad _UIApplicationHandleEventFromQueueEvent + 17370
12 UIKit 0x000000010b345233 _UIApplicationHandleEventQueue + 1961
13 CoreFoundation 0x000000010a9f3ad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010a9e999d __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010a9e8fd4 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010a9e8a06 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010db299f0 GSEventRunModal + 161
18 UIKit 0x000000010b348550 UIApplicationMain + 1282
19 Sliked 0x0000000109273a4e top_level_code + 78
20 Sliked 0x0000000109273a8a main + 42
21 libdyld.dylib 0x000000010cdc6145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我的代码如下所示:
@IBOutlet var followUnfollowButton: UIButton!
@IBAction func followUnfollow (sender: AnyObject) {
let user:PFObject = userPassed
let currentUser = PFUser.currentUser()
let relation : PFRelation = currentUser.relationForKey("KfriendsRelation")
if !followUnfollowButton.selected {
followUnfollowButton.selected = true
followUnfollowButton.setTitle("Unfollow", forState: UIControlState.Selected)
followUnfollowButton.backgroundColor = UIColor(red: 117/255, green: 201/255, blue: 223/255, alpha: 1.0)
relation.addObject(user)
PFUser.currentUser().saveInBackgroundWithBlock { (succeed:Bool, error: NSError!) -> Void in
if error != nil {
println("not working")
}
println("following user succes")
}
}
else {
followUnfollowButton.selected = false
followUnfollowButton.backgroundColor = UIColor(red: 248/255, green: 255/255, blue: 9/255, alpha: 1.0)
relation.removeObject(user)
PFUser.currentUser().saveInBackgroundWithBlock{ (succeed:Bool, error: NSError!) -> Void in
if error != nil {
println(error)
println("can't unfollow user")
}
}
}
}
我试图删除 Parse 逻辑,只是为了测试当我按下按钮时对所选状态的更改是否正常工作但有相同的错误。
这很奇怪,我错过了什么?
【问题讨论】:
-
"sent to instance..." 接下来是什么意思。这几乎是您切断的错误消息中最重要的部分。
-
检查我编辑的帖子
-
您在某处调用函数
followButton:,但您的代码中似乎没有该函数。我建议对“followButton”进行项目搜索 -
您正在启用某种事件处理程序并指定
followButton:作为处理事件的方法。但它被“发送”到视图控制器,而不是预期的对象。