0
我使用xcode 4.6
創建iPhone應用程序。 我有三個ViewControllers
A,B和C.他們都是桌面控制器。我希望用戶在ViewcontrollerA
和ViewcontrollerB
中選擇多行。然後ViewControllerC
將顯示選定的項目。這是可能的,我該怎麼做?Xcode 4.6將選定的行傳遞給新的UItableview
我使用xcode 4.6
創建iPhone應用程序。 我有三個ViewControllers
A,B和C.他們都是桌面控制器。我希望用戶在ViewcontrollerA
和ViewcontrollerB
中選擇多行。然後ViewControllerC
將顯示選定的項目。這是可能的,我該怎麼做?Xcode 4.6將選定的行傳遞給新的UItableview
首先,您應該爲所有的表格設置[self.tableView setAllowsMultipleSelection:YES]
。從技術文檔,
If you call indexPathsForSelectedRows, you can get the index paths that identify the selected rows.
假設你已經在你的C一ViewControllerA/B *屬性,你可以做像這樣:
在ViewControllerC.m:
- (void)makeCellsSelected
{
for (NSIndexPath *indexPath in [self.viewControllerA indexPathsForSelectedRows]) {
[[self.tableView cellForRowAtIndexPath:indexPath] setSelected:YES];
}
}
編輯甚至更容易將如下所示: ViewControllerB.m:
ViewControllerC *vcC = [ViewControllerC alloc] init];
for (NSIndexPath *indexPath in [self.tableView indexPathsForSelectedRows]) {
[[vcC.tableView cellForRowAtIndexPath:indexPath] setSelected:YES];
}
[self.navigationController pushViewController:vcC animated:YES];
所以你的C會出現在已經選好的行中