【问题标题】:Core Data Inverse RelationShip核心数据逆向关系
【发布时间】: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 是核心数据中的关系。 请帮忙..

【问题讨论】:

    标签: iphone core-data


    【解决方案1】:

    在您的 RestaurantViewController 中创建一个属性 Restaurant* currentRestaurant
    在 CityViewController 的 didSelectRowAtIndexPath: 中,将属性设置为 self.restaurantVC.currentRestaurant = [arrayOfRestaurants objectAtIndex:indexPath.row];

    【讨论】:

    • 非常感谢...我犯了一个非常愚蠢的错误..我在写 self.restaurantVC.currentRestaurant = [arrayOfRestaurant objectAtIndex:indexPath.row]; self.navigationcontroller pushviewcontroller 之后... :P
    猜你喜欢
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多