2017-06-15 103 views
0

我的桌面布局是这样的,我有一个固定的搜索栏在桌面视图的顶部。因此,搜索栏保持在顶部,并且不会与UITableView一起滚动。虽然我有我想要的布局,但我的tableView没有显示单元细节(显示空白)。请有人建议我去哪里错了?在桌面顶部锁定搜索栏

我的布局:

enter image description here

enter image description here

TestTableViewController

class TestTableViewController: UIViewController, UITableViewDelegate, UISearchBarDelegate{ 

var itemstore: ItemStore! 



// Sets how many rows in the table view to display 
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return itemstore.allItems.count 
} 


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    // Get a new or recycled cell 
    let cell = UITableViewCell(style: .value1, reuseIdentifier: "UITableViewCell") 
    let name = itemstore.allItems[indexPath.row] 
    cell.textLabel?.text = name 

    return cell 
} 
} 

ItemStore

class ItemStore { 

var allItems = ["Thanh", "David", "Tommy", "Maria"] 

} 

AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    // Create ItemStore instance 
    let itemStoreObject = ItemStore() 
    let itemController = window!.rootViewController as! TestTableViewController 
    itemController.itemstore = itemStoreObject 

    return true 
} 
+1

你在Interface Builder中连接了表视图数据源和委托吗? – paulvs

+0

请你能扩展你的问题。我不知道该怎么做。 – tim

+0

你IBOutlet你的桌面? 还检查你连接tableview数据源和委托? – iUser

回答

0

在cellForRowAt函数中放置一个断点,看看是否可以到达那里。如果未达到断点,检查数据源并委托接线。你可能希望在您的viewDidLoad中的功能是这样的:

self.tableView.dataSource = self 
self.tableView.delegate = self 

如果达到了破发点,但您仍看不到任何东西,检查高度为每个小区。