0
這是我現在的代碼,這是錯誤的。由於視圖的改變,我沒有得到viewDidLoad。如何將代表和數據源設置爲UITableViewController的視圖?
UITableView *tableView = [[UITableView alloc] init];
tableViewController = [[TableViewController alloc] init];
tableViewController.view = tableView;
tableViewController.title = @"test";
tableView.delegate = self;
tableView.dataSource = self;
我真正需要的是改變tableViewController
的觀點的delegate
和datasource
我self
。
問題是我出於某種原因不能這樣做。
類似的東西將是巨大的:
tableViewController = [[TableViewController alloc] init];
tableViewController.title = @"test";
tableViewController.view.delegate = self;
tableViewController.view.dataSource = self;
但由於某些原因,我不能設置tableViewController
的看法財產的委託,也沒有數據源。
任何想法爲什麼?
感謝
TableViewController是一個UITableViewController嗎? view是UIViewController的一個屬性,它返回一個UIView,它沒有委託或數據源。但是,UITableViewController具有tableView的tableView屬性。這些對象是相同的東西,但調用視圖會將其轉換爲UIView。只需使用.tableView。此外,在這種情況下,您不想創建和分配UITableView。如果TableViewController只是像Brandon的答案那樣的UIViewController子類,那麼您將需要創建自己的tableview。 – Matt