2017-06-15 102 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 

如果達到了破發點,但您仍看不到任何東西,檢查高度爲每個小區。