【发布时间】:2013-12-05 13:01:08
【问题描述】:
我的第一个 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;
}
将不胜感激。
【问题讨论】:
-
这是一个很好的教程。也许你可以看看link
标签: ios objective-c uitableview plist