2011-04-12 42 views
1

我使用的核心数据制作旅游指南应用程序。我有4个实体CITY,RESTAURANTS, 酒店和名胜。城市与所有其他实体相关,因为一个城市可能有多家餐馆,酒店和地方。城市实体有3个属性Name,Image,Description。我能够在接下来的view.But显示所选city.In餐厅实体的名单餐馆我有4个属性的名称,描述,地址和电话no..Now我想表明 选择餐厅的这个属性的细节(选择城市)我如何在下一个视图中访问餐馆描述。 这是我的代码。核心数据反比关系

 - (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是核心数据的关系.. 帮助请..

回答

2

在你RestaurantViewController在你的CityViewController的didSelectRowAtIndexPath:设定self.restaurantVC.currentRestaurant = [arrayOfRestaurants objectAtIndex:indexPath.row];

+1

感谢属性创建一个属性Restaurant* currentRestaurant
你非常...我犯了一个非常愚蠢的错误..我写self.restaurantVC.currentRestaurant = [arrayOfRestaurants objectAtIndex:indexPath.row];在self.navigationcontroller pushviewcontroller ...之后:P – Abhishek 2011-04-12 12:45:39