我的第一个Table View应用程序需要更多帮助。 我有.plist与各大洲,国家和其他信息:
我使用StoryBoard,我有3个视图控制器(MasterVC - 适用于各大洲,MiddleVC - 适用于国家/地区,DetailVC - 详细信息)。我已经在我的MysterVC上的UITableView中显示了大陆。现在我想传递有关推送到MiddleVC的信息,例如欧洲被推,并在我的MiddleVC上以表格形式显示欧洲国家。
我想我应该在didSelectRowAtIndexPath:
中这样做- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
//is it correct way to catch the info about which continent was pressed?
NSString *ContinentName = [[world allKeys] objectAtIndex:indexPath.row];
//I don't know how to pass the info forward
}
或许我应该使用segue传递数据?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showMiddle"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
//??is everything what needed here??
[[segue destinationViewController] setDetailItem:object];
}
}
我不知道如何处理来自MasterVC的传递信息,这是在MiddleVC。虽然我准备了一些初步编码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//I think countries arrays will be needed here
NSArray *namesOfAfricanCountries = [africa allKeys];
NSString *AfricanCountryName = [namesOfAfricanCountries objectAtIndex:indexPath.row];
NSArray *namesOfEuropeanCountries = [europe allKeys];
NSString *EuropeanCountryName = [namesOfEuropeanCountries objectAtIndex:indexPath.row];
//how to feel cells only with the proper continent's countries?
cell.textLabel.text = ???;
return cell;
}
非常感谢您的帮助。
答案 0 :(得分:0)
您使用的是UINavigationController吗?如果是这样的话:
然后在详细VC'cellForRowAtIndexPath:
中NSString * key = [self.continentDict allKeys] [indexPath.row];
cell.textLabel.text = key;