ios swift uitableview sections with different tabledata -
i have list of data coming in json. list load tableview within 2 seperate sections called featured , all. trying figure out how "featured" section not load same amount of rows "all" section. section featured section shows featured list plus 16 empty rows. ideas on how rid of these rows in featured section?
func tableview(tableview: uitableview, titleforheaderinsection section: int) -> string? { if(section == 0) { return "featured" } return "all" } func numberofsectionsintableview(tableview: uitableview) -> int { var sections: int = 2 return sections } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { var count: int = tabledata.count println("tabledata \(count)") return count } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { //let session = nsurlsession.sharedsession() tableview.estimatedrowheight = 44.0 tableview.rowheight = uitableviewautomaticdimension let cell: uitableviewcell = uitableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: "cell") let entry : nsmutabledictionary = self.tabledata[indexpath.row] as! nsmutabledictionary var featured = entry["business_isfeatured"] as? string if ((featured == "1") && (indexpath.section == 0)) { var busname = entry["business_name"] as? string var points = entry["member_points"] as? string var imagename = entry["business_image"] as? string var imgurl: nsurl = nsurl(string: "http://www.example.com/images/\(imagename!)")! let request: nsurlrequest = nsurlrequest(url: imgurl) nsurlconnection.sendasynchronousrequest( request, queue: nsoperationqueue.mainqueue(), completionhandler: {(response: nsurlresponse!,data: nsdata!,error: nserror!) -> void in if error == nil { cell.textlabel!.text = busname cell.textlabel!.numberoflines = 0 cell.detailtextlabel!.text = "points: \(points!)" cell.imageview!.image = uiimage(data: data) } }) } else { if((featured == "0") && (indexpath.section == 1)) { var busname = entry["business_name"] as? string var points = entry["member_points"] as? string var imagename = entry["business_image"] as? string var imgurl = nsurl(string: "http://www.example.com/images/\(imagename!)") cell.textlabel!.text = busname cell.textlabel!.numberoflines = 0 cell.detailtextlabel!.text = "points: \(points!)" cell.imageview!.hnk_setimagefromurl(imgurl!, format: format<uiimage>(name: "original")) } } return cell }
your implementation of uitableviewdatasource's
func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int
method needs supply number of rows intend each section contain. code returns same number of rows regardless of section, sounds wrong based on how describe want do. need calculate , return number of featured items featured section, rather size of entire dataset.
Comments
Post a Comment