I’m new to iOS growth. Currently, I’m engaged on a venture in which I use greater than two UITableView
s in a single view controller, however each information sources come from server one after the other. When the primary api hit, it reveals the end result, however after choose merchandise from that checklist I’m unable to present the response in checklist.
Here is my code:
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
print("sdfsdfsf")
var rely:Int?
if tableView == self.pat_search_listview {
rely = serach_data.rely
}
else if tableView == self.visit_listview {
rely = all_vist_data.rely
}
return rely!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if tableView == self.pat_search_listview {
cell.textLabel?.textual content = serach_dataindexPath.row.title + " " + serach_dataindexPath.row.id
}
else if tableView == self.visit_listview {
print("second listview")
cell.textLabel?.textual content = all_vist_dataindexPath.row.date
}
return cell
}
test the Outlet connections for each tableViews… each shouldn’t be nil in viewDidLoad
in viewDidLoad:
self.pat_search_listview.dataSource = self;
self.visit_listview = self;
self.pat_search_listview.tag = 0
self.visit_listview.tag = 1
in
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView.tag == 0
...
else
...
Make certain to set delegate and information supply and don’t overlook to reload the desk after including/updating the arrays.
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int
{
if tableView == self.pat_search_listview
{
return serach_data.rely/*pat_search_listview's Array rely*/
}
else if tableView == self.visit_listview
{
return all_vist_data.rely/*visit_listview Array rely*/
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if tableView == self.pat_search_listview
{
cell.textLabel?.textual content = serach_dataindexPath.row.title + " " + serach_dataindexPath.row.id
}
else if tableView == self.visit_listview
{
print("second listview")
cell.textLabel?.textual content = all_vist_dataindexPath.row.date
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if tableView == self.pat_search_listview
{
//--- Item at index from pat_search_listview
}
else if tableView == self.visit_listview
{
print("second listview")
//--- Item at index from visit_listview
}
}