【问题标题】:Data Access in Master DetailView with multiple Xib for DetailMaster DetailView 中的数据访问与多个 Xib for Detail
【发布时间】:2012-03-16 05:55:26
【问题描述】:

我有一个类似 userName,DOB,Registation No: 和 Address 的数据,我为它创建了 10 个 XIB 文件 对于打开的详细视图当单击 MasterView 表单元格时,在详细视图的第二个 XIB 文件中,当我在第二个 Xib 中选择用户时,我有一个用户信息,我如何在我的第 3 到第 10 个 XIB 中访问该数据??我不知道 iphone bcoz m new in iphone development 中的数据委托??

【问题讨论】:

    标签: iphone objective-c ios4 uiview


    【解决方案1】:

    根据我对您的项目的理解:

    1. 您从 MasterViewController(第一个控制器)开始
    2. 选择或单击行/单元格后,另一个控制器加载,其中包含 用户列表? (我不太确定)其中每个用户都有信息(包含用户名、出生日期等)。因此,这意味着在此控制器中 - 您将这些信息分配给相应的用户。 (第二控制器)
    3. 然后,当您选择特定用户时,另一个控制器会加载到您想要使用来自该控制器的数据的位置 - 可能是您想要显示从第二个控制器分配的那些信息的位置。 (第三控制器)

    所以,如果我们在同一页面上,这就是您要执行的操作:

    (假设你已经完成了 MainView (FirstController) 并且你已经在 SecondViewController 中了)

    对于初学者,您可以这样做:

    1. 在 ThirdViewController 中创建一个全局变量,该变量将保存 SecondViewController 传递的信息。在这种情况下,

    ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~///////// ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ThirdViewController.h~~~~~~~~~ ~~~~~~~~~~~~~~~~~~///////// ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/////////

    @interface ThirdViewController:UIViewController{
        NSDictionary *dictInformation;
    }
    @property (nonatomic, retain) NSDictionary *dictInformation;
    @end
    
    @implementation ThirdViewController
    @synthesize dictInformation;
    
    ...
       // some codes here...
       // you can use the information passed from the SecondViewController
    ...
    
    - (void)dealloc{
         [dictInformation release], dictInformation = nil;
         [super dealloc];
    }
    @end
    

    ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~///////// ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SecondViewController.h~~~~~~~~~ ~~~~~~~~~~~~~~~~///////// ////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/////////

    @implementation SecondViewController
    
        // This is the assignment of data. You can put this in viewDidload
        // user 1
         NSMutableDictionary *aUser1 = [[NSMutableDictionary alloc] init];
        [aUser1 setObject:@"josh123" forKey:@"userName"];
        [aUser1 setObject:@"01-01-1987" forKey:@"dateOfBirth"];
        [aUser1 setObject:@"12345678" forKey:@"regNumber"];
        [aUser1 setObject:@"24-H 1st St. New York" forKey:@"address"];
        // user 2
        NSMutableDictionary *aUser2 = [[NSMutableDictionary alloc] init];
        [aUser2 setObject:@"josh321" forKey:@"userName"];
        [aUser2 setObject:@"01-02-1988" forKey:@"dateOfBirth"];
        [aUser2 setObject:@"87654321" forKey:@"regNumber"];
        [aUser2 setObject:@"42-H 1st St. New York" forKey:@"address"];
    
       // I assigned all users to an array
        NSArray *arrayOfUsers = [[NSArray alloc] initWithObjects:aUser1, aUser2, nil];
        [aUser1 release];
        [aUser2 release];
    
       // Pass the value of arrayOfUsers somewhere to that it can be accessed
       // or it can be a 
    
       /* At this point, the following has values:
       arrayOfUsers[0] = aUser1 -> {'josh123', '01-01-1987', '12345678', '24-H 1st St. New York'}
       arrayOfUsers[1] = aUser2 -> {'josh321', '01-02-1988', '87654321', '42-H 1st St. New York'}
       */
    
        // You can actually add the following codes anywhere, depending on your implementation. It can be when you clicked a cell or a button, etc.
    
          ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
        // assign a dictionary value to dictInformation which is found in ThirdViewController
        // If you are using UITableView, then, this should be done when you are selecting a cell in the tableView and the value of the index should be indexPath.row
          [thirdViewController setDictInformation:[arrayOfUsers objectAtIndex:0]]; 
          // This pushes to the ThirdViewController
          [self.navigationController pushViewController:thirdViewController animated:YES];
          [thirdViewController release];
    
          ...
    @end
    

    注意:这只是代码片段...我只是想告诉你如何去做。不过,希望这会有所帮助。祝你好运! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-24
      • 2021-11-11
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      相关资源
      最近更新 更多