2012-03-16 48 views
0

我有一個像userName,DOB,註冊編號:和地址,我創建了10個XIB文件 細節查看哪個是打開的當點擊MasterView表單元格,在第二個詳細信息視圖的XIB文件我有一個用戶的信息,當我選擇第二個Xib中的用戶時,如何在我的第3至第10個XIB中訪問該數據?我不知道iphone中的數據委託bcoz新的iPhone開發?詳細數據訪問與多個Xib詳細

回答

0

在我對你的項目的理解:

  1. 你開始與MasterViewController(第一控制器)
  2. 選擇或點擊一個行/單元格後,另一個控制器負載包含 用戶的列表? (我不太確定),其中每個用戶都有信息(包含userName,DOB等)。所以,這意味着在這個控制器中 - 您將這些信息分配給相應的用戶。 (第二個控制器)
  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 

注意:這僅僅是一個代碼片段......我只想給你一個關於如何去做的想法。但希望這有助於。祝你好運! :)