我是能夠實現你正在尋找在第一視圖控制器下面的代碼做什麼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// create the new table view
TestTableViewController2 *testView2 = [TestTableViewController2 new];
// get a reference to the cell that they clicked and create a totally new cell, a 'copy' of
// the original that we can pass to the next view
UITableViewCell *clickedCell = [tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *clickedCellCopy = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
clickedCellCopy.textLabel.text = clickedCell.textLabel.text;
clickedCellCopy.detailTextLabel.text = clickedCell.detailTextLabel.text;
// set this new cell as the header cell on the new view
testView2.myHeaderCell = clickedCellCopy;
// push the new view onto the stack
[self.navigationController pushViewController:testView2 animated:YES];
}
然後將屬性添加到您的第二個表格視圖控制器:
@property (nonatomic, retain) UITableViewCell *myHeaderCell;
然後在.M的viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
// set our header cell as the table view's header
self.tableView.tableHeaderView = self.myHeaderCell;
}
這給了我下面的結果:
https://www.dropbox.com/s/t42lraue1kfolf3/cell%20demo.mov?dl=0
謝謝大家的好回答:+1。我將根據哪一個最適合我來執行並報告回來。非常感謝你的幫助。 – learner 2014-09-05 21:15:19