ios - Swift UITableView Return Cell From Array of Arrays -
i'm messing around swift, building table view controller using pre-generated cells, rather reusing cells, , have array holds arrays of mycustomcell's, example:
let sections = [[cell1, cell2, cell3], [cell4, cell5], [cell6]]
thus, in numberofsectionsintableview i'm doing following:
override func numberofsectionsintableview(tableview: uitableview?) -> int { homecoming sections.count } .. , in numberofrowsforsection i'm doing:
override func tableview(tableview: uitableview?, numberofrowsinsection section: int) -> int { homecoming sections[section].count } this working fine , dandy. when attempting grab cell array i'm having more hard time, seeing sorts of different issues , know best way implement this. following, seems simplest method, , i've implemented same thing in few different forms, can't build project , resulting error:
override func tableview(tableview: uitableview?, cellforrowatindexpath indexpath: nsindexpath?) -> uitableviewcell? { var arrayforsection = sections[indexpath!.section] var cell: mycustomcell = arrayforsection[indexpath!.row] mycustomcell homecoming cell } while emitting sil 'tableview' @ /users/blah/blah/blah/mycustomcell/mycustomcell example/mycustomcell example/exampletableviewcontroller.swift:125:14 :0: error: unable execute command: segmentation fault: 11 :0: error: swift frontend command failed due signal (use -v see invocation) command /applications/xcode6-beta.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/swift failed exit code 254 not sure issue here, can come simple implementation homecoming appropriate cell , compile?
not sure if seeing seg-fault bug or not, changing code in cellforrowatindexpath next seems trick:
override func tableview(tableview: uitableview?, cellforrowatindexpath indexpath: nsindexpath?) -> uitableviewcell? { allow cellsforsection: mycustomcell[] = sections[indexpath!.section] array homecoming cellsforsection[indexpath!.row] mycustomcell } alternatively, beingness more specific types when creating variables makes more simple. changing this:
var sections = [] var firstsectioncells = [] var secondsectioncells = [] var thirdsectioncells = [] sections = [firstsectioncells, secondsectioncells, thirdsectioncells] // later to this:
var sections: mycustomcell[][] = [] var firstsectioncells: mycustomcell[] = [] var secondsectioncells: mycustomcell[] = [] var thirdsectioncells: mycustomcell[] = [] sections = [firstsectioncells, secondsectioncells, thirdsectioncells] // later results in beingness able instead, bit more concise:
override func tableview(tableview: uitableview?, cellforrowatindexpath indexpath: nsindexpath?) -> uitableviewcell? { allow cellsforsection = sections[indexpath!.section] homecoming cellsforsection[indexpath!.row] } ios uitableview segmentation-fault swift
No comments:
Post a Comment