ios - Scrolling to Bottom of UITableView When Messages Load -
i'm trying figure out how scroll bottom of uitableview once messages database load it. i've tried using tableview.setcontentoffset(cgpointmake(0, cgfloat.max), animated: true)
table goes having messages in nothing @ all. i've tried
var ipath = nsindexpath(forrow: messagesarray.count - 1, insection: 0) tableview.scrolltorowatindexpath(ipath, atscrollposition: uitableviewscrollposition.bottom, animated: true)
but exc_bad_access code = 1
. appreciated.
edit:
i'm putting code in viewdidappear() function right after parse finds data query.findobjectsinbackgroundwithblock(...), not sure if makes difference or not.
here's query code:
query.findobjectsinbackgroundwithblock { (object, error) -> void in if (error == nil) { var = 0; < object!.count; i++ { var messageobject = messages() messageobject.messageid = object![i]["messageid"] as! string println("message id") println(messageobject.messageid) messageobject.messagetext = object![i]["message"] as! nsstring string println("message text") println(messageobject.messagetext) messageobject.recipientid.append(object![i]["recipientid"] as! nsstring string) println("recipient") println(messageobject.recipientid[0]) messageobject.senderid = object![i]["senderid"] as! nsstring string messageobject.timestamp = object![i]["timestamp"] as! nsstring string println("timestamp") println(messageobject.timestamp) dispatch_async(dispatch_get_main_queue(), { () -> void in self.messagesarray.append(messageobject) }) } self.loadobjects() self.tableview.reloaddata() self.tableview.setcontentoffset(cgpointmake(0, cgfloat.max), animated: true) } }
please try one
in objective-c
nsinteger bottomrow = [self.dataarr count] - 1; // count's array. if (bottomrow >= 0) { nsindexpath *indexpath = [nsindexpath indexpathforrow:bottomrow insection:0]; [self.tblview scrolltorowatindexpath:indexpath atscrollposition:uitableviewscrollpositiontop animated:animated]; }
in swift
var bottomrow : nsinteger = dataarr.count-1; if (bottomrow >= 0) { var indexpath : nsindexpath = nsindexpath(forrow: bottomrow, insection: 0) tblview.scrolltorowatindexpath(indexpath, atscrollposition: uitableviewscrollposition.bottom, animated: true) }
Comments
Post a Comment