2016-01-28 77 views
-1

我試圖從數據庫中獲取數據到幻燈片菜單。我正在使用下面的代碼來獲取數據,並且需要連接到UI中存在的按鈕。如何通過數組快速傳遞數據到按鈕

func fetchiingcontact() 
    { 
     var allusers:NSMutableArray = NSMutableArray() 
     allusers = ModelManager.getInstance().getAlldrawerData()//Fetching contacts objects from Sqlite 
     for var i = 0 ; i < allusers.count ; i++ 
     { 
      var userobject : user = user() 
      userobject = allusers.objectAtIndex(i) as! user 
      let contactobjectuser:UserContactsClass = UserContactsClass() 


      let userdefault = NSUserDefaults.standardUserDefaults() 
      let ownuserid = userdefault.integerForKey("Userid") 
      if(userobject.userid == ownuserid) 
      { 

      } 
      else 
      { 
       contactobjectuser.firstName = userobject.firstName 
       contactobjectuser.lastName = userobject.lastName 
       contactobjectuser.profilePic = userobject.profilePic 
       contactobjectuser.nickName = userobject.nickName 


       usercontactslistarray.addObject(contactobjectuser) 
       self.secondLabel.text = contactobjectuser.lastName 
      self.userFlname.text = contactobjectuser.firstName 
      } 


     } 

我如何通過代碼usercontactslistarray連接到UI按鈕爲self.secondlabel.text不工作

+0

你似乎不與SQLite或獲取數據有關。這部分看起來很好。 – rmaddy

回答

1

您可以使用

self. userFlname.setText(contactobjectuser.lastName) 
self.secondLabel.setText(contactobjectuser.lastName) 
+0

它給出了錯誤值的類型'uilabel'沒有settext成員'setText' – Nick

1
let string = "Your Text" 

yourButton.setTitle(string as String, forState: UIControlState.Normal) 
+0

我有一個標籤,它是從sqlite數據庫獲取數據,所以我需要更改用戶名每次用戶登錄 – Nick