我收到错误:
Cannot call value of non-function type ‘JsQMessagesCollectionVIEw!’ at the following line of code:
let cell = super.collectionVIEw(collectionVIEw,cellForItemAtIndexPath: indexPath) as! JsQMessagesCollectionVIEwCell
这是我的整个上下文功能:
func collectionVIEw(collectionVIEw: UICollectionVIEw,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionVIEwCell{ let cell = super.collectionVIEw(collectionVIEw,cellForItemAtIndexPath: indexPath) as! JsQMessagesCollectionVIEwCell let message = messages[indexPath.item] if message.senderID == senderID { cell.textVIEw!.textcolor = UIcolor.whitecolor() } else { cell.textVIEw!.textcolor = UIcolor.blackcolor() } return cell}
有人有想法吗?
附:如果这有帮助,这是我的整个代码块:
import UIKitimport Firebaseimport JsQMessagesVIEwControllerclass ChatVIEwController: JsQMessagesVIEwController { // MARK: PropertIEs var rootRef = FIRDatabase.database().reference() var messageRef: FIRDatabaseReference! var messages = [JsQMessage]() var outgoingBubbleImageVIEw: JsQMessagesBubbleImage! var incomingBubbleImageVIEw: JsQMessagesBubbleImage! var userIsTy@R_404_6817@Ref: FIRDatabaseReference! // 1 private var localTy@R_404_6817@ = false // 2 var isTy@R_404_6817@: Bool { get { return localTy@R_404_6817@ } set { // 3 localTy@R_404_6817@ = newValue userIsTy@R_404_6817@Ref.setValue(newValue) } } var usersTy@R_404_6817@query: FIRDatabasequery! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Change the navigation bar background color to blue. // navigationController!.navigationbar.barTintcolor = UIcolor.init(red:252/255,green: 87/255,blue: 68/255,Alpha: 1) navigationController!.navigationbar.barTintcolor = UIcolor.init(red:250/255,green: 69/255,blue: 85/255,Alpha: 1) Title = "RoastChat" setupBubbles() // No avatars collectionVIEw!.collectionVIEwLayout.incomingAvatarVIEwSize = CGSize.zero collectionVIEw!.collectionVIEwLayout.outgoingAvatarVIEwSize = CGSize.zero // Remove file upload icon self.inputToolbar.contentVIEw.leftbarbuttonItem = nil; messageRef = rootRef.child("messages") } func vIEwDIDAppear(animated: Bool) { super.vIEwDIDAppear(animated) observeMessages() observeTy@R_404_6817@() } func vIEwDIDdisappear(animated: Bool) { super.vIEwDIDdisappear(animated) } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageData! { return messages[indexPath.item] } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageBubbleImageDataSource! { let message = messages[indexPath.item] // 1 if message.senderID == senderID { // 2 return outgoingBubbleImageVIEw } else { // 3 return incomingBubbleImageVIEw } } func collectionVIEw(collectionVIEw: UICollectionVIEw,numberOfItemsInSection section: Int) -> Int { return messages.count } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageAvatarImageDataSource! { return nil } private func setupBubbles() { let factory = JsQMessagesBubbleImageFactory() outgoingBubbleImageVIEw = factory?.outgoingMessagesBubbleImage( // UIcolor.init(red:250/255,Alpha: 1)) with: UIcolor.init(red:47/255,green: 53/255,blue: 144/255,Alpha: 1)) incomingBubbleImageVIEw = factory?.incomingMessagesBubbleImage( with: UIcolor.Jsq_messageBubblelightGray()) } func addMessage(ID: String,text: String) { let message = JsQMessage(senderID: ID,displayname: "",text: text) messages.append(message!) } func collectionVIEw(collectionVIEw: UICollectionVIEw,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionVIEwCell{ let cell = super.collectionVIEw(collectionVIEw,cellForItemAtIndexPath: indexPath) as! JsQMessagesCollectionVIEwCell let message = messages[indexPath.item] if message.senderID == senderID { cell.textVIEw!.textcolor = UIcolor.whitecolor() } else { cell.textVIEw!.textcolor = UIcolor.blackcolor() } return cell } func dIDPressSendbutton(button: UIbutton!,withMessageText text: String!,senderID: String!,senderdisplayname: String!,date: NSDate!) { let itemRef = messageRef.childByautoID() // 1 let messageItem = [ // 2 "text": text,"senderID": senderID ] itemRef.setValue(String(messageItem)) // 3 // 4 JsQSystemSoundplayer.Jsq_playMessageSentSound() // 5 finishSendingMessage() isTy@R_404_6817@ = false } private func observeMessages() { // 1 let messagesquery = messageRef.querylimited(tolast: 25) // 2 messagesquery.observe(.childAdded) { (snapshot: FIRDataSnapshot!) in // 3 let ID = snapshot.value!["senderID"] as! String let text = snapshot.value!["text"] as! String // 4 self.addMessage(ID: ID,text: text) // 5 self.finishReceivingMessage() } } private func observeTy@R_404_6817@() { let ty@R_404_6817@IndicatorRef = rootRef.child("ty@R_404_6817@Indicator") userIsTy@R_404_6817@Ref = ty@R_404_6817@IndicatorRef.child(senderID) userIsTy@R_404_6817@Ref.ondisconnectRemoveValue() // 1 usersTy@R_404_6817@query = ty@R_404_6817@IndicatorRef.queryOrderedByValue().queryEqual(tovalue: true) // 2 usersTy@R_404_6817@query.observe(.value) { (data: FIRDataSnapshot!) in // 3 You're the only ty@R_404_6817@,don't show the indicator if data.childrenCount == 1 && self.isTy@R_404_6817@ { return } // 4 Are there others ty@R_404_6817@? self.showTy@R_404_6817@Indicator = data.childrenCount > 0 self.scrollToBottom(animated: true) } } func textVIEwDIDChange(textVIEw: UITextVIEw) { super.textVIEwDIDChange(textVIEw) // If the text is not empty,the user is ty@R_404_6817@ isTy@R_404_6817@ = textVIEw.text != "" } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,attributedTextForCellBottomLabelAtIndexPath indexPath: NSIndexPath!) -> AttributedString! { return AttributedString(string:"test") }}尝试将方法更改为:
overrIDe func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: NSIndexPath) -> UICollectionVIEwCell{ let cell = super.collectionVIEw(collectionVIEw,cellForItemAt: indexPath) as! JsQMessagesCollectionVIEwCell let message = messages[indexPath.item] if message.senderID == senderID { cell.textVIEw!.textcolor = UIcolor.whitecolor() } else { cell.textVIEw!.textcolor = UIcolor.blackcolor() } return cell}
如果您正在正确编写重写方法,Swift会抱怨缺少overrIDe关键字.因此,如果您在此重写方法上找不到任何警告或错误,则很可能会滥用方法签名.
并且许多UICollectionVIEwDataSources方法都被重命名,在Swift3中“cellForItemAtIndexPath”有这个签名:
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell
所以,Swift找不到匹配collectionVIEw(_:cellForItemAtIndexPath :)的方法定义,所以假设collectionVIEw会有一个属性. (不幸的是,它在JsQMessagesVIEwController中声明.)
您可能在类中有这种不匹配的方法实现.更好地检查它们.
总结以上是内存溢出为你收集整理的swift – “不能调用非函数类型的值”全部内容,希望文章能够帮你解决swift – “不能调用非函数类型的值”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)