【发布时间】:2011-08-03 19:11:45
【问题描述】:
我正在使用核心数据创建旅行指南应用。我有 4 个实体 CITY ,RESTAURANTS , 酒店和著名的地方。城市与所有其他实体相连,因为一个城市可能有许多餐馆、旅馆和场所。城市实体有 3 个属性名称、图像、描述。我可以显示所选城市的餐厅列表。在餐厅实体中,我有 4 个属性名称、描述、地址和电话号码。现在我想显示 下一个视图中所选餐厅(所选城市)的此属性详细信息。但是如何在下一个视图中访问餐厅描述.. 这是我的代码。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSMutableArray *restaurants = [[NSMutableArray alloc]initWithArray:[city.cityTorestaurants allObjects]];
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc]initWithKey:@"Name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:nameDescriptor,nil];
[restaurants sortUsingDescriptors:sortDescriptors];
[hotels sortUsingDescriptors:sortDescriptors];
[self setArrayOfRestaurants:restaurants];
[restaurants release];
[nameDescriptor release];
[sortDescriptors release];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil ) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]autorelease];
}
//set up cell
NSLog(@"For Restaurants List");
Restaurants *restaurants = [arrayOfRestaurants objectAtIndex:indexPath.row];
cell.textLabel.text = restaurants.Name;
return cell;
}
cityTorestaurants 和 restaurantTocity 是核心数据中的关系。 请帮忙..
【问题讨论】: