2011-04-12 46 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