ios - Tableview Like Snapchat Send Feature (Multiple Selection and Swipeable Label) -
in xcode project have similar view snapchat's "send to..." screen (i have attached screenshot). have made tableview , populate , have allowed multiple selection on. having trouble 2 things:
1) multiple selection: can select cell want, when tap on search bar , start typing, previous selections go away. assuming need add of names in array , somehow communicate array table shows if username in array make selected in tableview. not sure how that. how can this?
2) sending bottom bar (blue in photo): may know, in snapchat press on users want send snap to, names added bar @ bottom, fill bar, because swipe able can horizontally scroll through names have added. can append names array , show array in label theirs, not know how make user can horizontally scroll through it.how implement same feature?
feel free answer of questions! not need of them, need them answered. here's code far:
class user { var userid:string? var userfullname:string? var userusername:string? var userprofileimage:pffile? var isprivate:bool init(userid : string, userfullname : string, userusername : string, userprofileimage : pffile, isprivate : bool) { self.userid = userid self.userfullname = userfullname self.userusername = userusername self.userprofileimage = userprofileimage self.isprivate = isprivate } } var userarray = [user]() func loadfriends() { //step 1: find friends let friendsquery = pfquery(classname: "friends") //choosing class friendsquery.wherekey("friendone", equalto: pfuser.current()?.objectid ?? string()) //finding friends friendsquery.limit = self.page //number of users intitally showing friendsquery.findobjectsinbackground (block: { (objects, error) -> void in if error == nil { //if no error //clean self.friendsarray.removeall(keepingcapacity: false) //step 2: find related objects depending on query setting object in objects! { self.friendsarray.append(object.value(forkey: "friendtwo") as! string) //hold array info of friend } //step 3: find friend info let query = pfuser.query() query?.wherekey("objectid", containedin: self.friendsarray) query?.adddescendingorder("createdat") //how order users query?.findobjectsinbackground(block: { (objects, error) -> void in if error == nil { object in objects! { var user : user let fullname = (object.value(forkey: "fullname") as! string) let username = (object.object(forkey: "username") as! string) let profilephoto = (object.object(forkey: "profilephoto") as! pffile) let objectid = (object.objectid!) let isprivate = (object.object(forkey: "isprivate") as! bool) user = user(userid: objectid, userfullname: fullname, userusername: username, userprofileimage: profilephoto, isprivate: isprivate) self.userarray.append(user) } self.tableview.reloaddata() } else { print(error!) } }) } else { print(error!) } }) } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "cell") as! friendcell let user = userarray[indexpath.row] //add user info cells cell.fullnamelabel.text = user.userfullname cell.usernamelabel.text = user.userusername cell.objectid = user.userid! cell.isprivate = user.isprivate user.userprofileimage?.getdatainbackground (block: { (data, error) in if error == nil { cell.profilephoto.image = uiimage(data: data!) } }) }) }
1) multiple selection: should have user class (e.g user) holds user properties instead of maintaining array
each property. store user object in array
. user class below:
class user { var userid:string var userfullname:string var username:string var userprofileimageurl:string init(userid:string,userfullname:string,username:string,userprofileimageurl:string) { self.userid = userid self.userfullname = userfullname self.username = username self.userprofileimageurl = userprofileimageurl } }
you have user extension check if user selected or not(e.g isselected).
import uikit import foundation private var selectedkey: uint8 = 0 extension user { var isselected:bool{ { return objc_getassociatedobject(self, &selectedkey) as! bool } set { objc_setassociatedobject(self, &selectedkey, newvalue, .objc_association_retain_nonatomic) } } }
now in func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell
check user.isselected == true/false
, update selected/deselected image accordingly. , update value of isselected
in func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath)
2) sending bottom bar: bottom bar add uicollectionview
subview in uiview
. create class overriding uicollectionviewcell
holds uilabel
. can add flow layout
in uicollectionview
.
i have given idea start with.hope you.
Comments
Post a Comment