@Ankit塔瓦:一切皆有可能
在didSelectRowAtIndexPath
創建表視圖中的同一個實例,並從那裏與數據源更新可在特定行推動它。如果您需要進一步的幫助,請告訴我。我以前做過這個。
例如,如果表視圖控制器被命名爲RootViewController
,您的didSelectRowAtIndexPath
方法應該是這樣的:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.navigationController viewControllers] count] < 3) {
RootViewController *detailViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
detailViewController.rootArray = [self.rootArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
和numberOfRowsInSection
:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [rootArray count];
}
rootArray
是包含可顯示以下的信息的陣列在當前的表視圖控制器中,並且是由一個主控陣列創建的,而之前在委託或其他可以訪問控制器的主控類中創建。像這樣(在委託創建在我的例子):
NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
NSArray *array2 = [NSArray arrayWithObjects:@"4", @"5", nil];
NSArray *array3 = [NSArray arrayWithObjects:@"6", @"7", nil];
NSArray *array4 = [NSArray arrayWithObjects:@"8", @"9", nil];
NSArray *array5 = [NSArray arrayWithObjects:@"10", @"11", @"12", nil];
NSArray *array6 = [NSArray arrayWithObjects:@"14", @"15", @"13", nil];
NSArray *array7 = [NSArray arrayWithObjects:@"16", @"17", nil];
NSArray *array8 = [NSArray arrayWithObjects:@"19", @"18", nil];
NSArray *array9 = [NSArray arrayWithObjects:@"20", @"21", @"22", nil];
NSMutableArray *mutable1 = [NSMutableArray arrayWithObjects:array1, array2, array3, nil];
NSMutableArray *mutable2 = [NSMutableArray arrayWithObjects:array4, array5, array6, nil];
NSMutableArray *mutable3 = [NSMutableArray arrayWithObjects:array7, array8, array9, nil];
self.initialArray = [NSMutableArray arrayWithObjects:mutable1, mutable2, mutable3, nil];
而且viewDidLoad
當前tableViewController,所以你必須在第一個載荷的數組:
- (void)viewDidLoad
{
[super viewDidLoad];
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
if ([[self.navigationController viewControllers] count] == 1) {
self.rootArray = appDelegate.initialArray;
}
}
我需要你的幫助。我知道如何修改數據源,但我不知道推UITableView。我該如何與你聯繫? – user403015
嗨,剛剛添加您的聯繫人在我的Skype。請接受我的請求。謝謝。 – user403015