2012-01-31 77 views
0

我正在學習Xcode 4.2與故事板並試圖製作一個通用的應用程序。Xcode 4.2與故事板 - 文本字段未分配

所有在iPhone上都可以正常工作,但iPad側有一個將3個文本字段(1個TextField,2個TextViews)分配給分割視圖控制器的詳細視圖的問題。

我在故事板中使用了新功能,將細節視圖中的新字段鏈接到詳細頭文件,並自動創建屬性和合成語句(非常棒的功能)。

但是,當我想要爲詳細字段賦值(方法drinkChanged)時,在DetailViewController視圖中不顯示任何內容。我驗證了字典值在分配時存在。

有趣的是,當viewWillAppear被調用時調用方法refreshView時,它會起作用。但是,如果方法refreshView由drinkChanged調用(意味着用戶在MasterViewController表上選擇了一行),那麼它不起作用。

有人知道我可能會錯過巴士嗎?

這裏是我的代碼:

MasterViewController.h

#import <UIKit/UIKit.h> 

@interface MasterViewController : UITableViewController { 
    NSMutableArray *drinks; 
} 

@property (nonatomic, retain) NSMutableArray *drinks; 

@end 

MasterViewController.m

#import "MasterViewController.h" 
#import "DetailViewController.h" 
#import "AddDrinkViewController.h" 
#import "DrinkConstants.h" 

@implementation MasterViewController 

@synthesize drinks; 
. 
. 
. 
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (!self.editing) { 

     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 

      NSLog(@"didSelectRowAtIndexPath...iPad"); 

      // Pass the selected object to the drinkChanged method in DetailViewController.m. 
      DetailViewController *splitViewDetailView = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
      [splitViewDetailView drinkChanged:[self.drinks objectAtIndex:indexPath.row]]; 
     } 
     else { 

      NSLog(@"didSelectRowAtIndexPath...iPhone"); 

      DetailViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 

      detailViewController.drink = [self.drinks objectAtIndex:indexPath.row]; 

      // Pass the selected object to the new view controller. 
      [self.navigationController pushViewController:detailViewController animated:YES]; 
     } 
    } 
    else { 

     AddDrinkViewController *editingDrinkVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AddDrink"]; 

     editingDrinkVC.drink = [self.drinks objectAtIndex:indexPath.row]; 
     editingDrinkVC.drinkArray = self.drinks; 

     [self.navigationController presentModalViewController:editingDrinkVC animated:YES]; 
    } 
} 

DetailViewController.h

#import <UIKit/UIKit.h> 

@interface DetailViewController : UIViewController { 

    NSDictionary *drink; 
} 

@property (strong, nonatomic) id detailItem; 
@property (nonatomic, retain) NSDictionary *drink; 

@property (strong, nonatomic) IBOutlet UITextField *nameTextField; 
@property (strong, nonatomic) IBOutlet UITextView *ingredientsTextView; 
@property (strong, nonatomic) IBOutlet UITextView *directionsTextView; 

- (void) refreshView; 
- (void) drinkChanged:(NSDictionary *) newDrink; 

@end 

DetailViewController。米

的NSLog輸出

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all 
Attaching to process 1187. 
2012-01-31 13:10:26.061 DrinkMixer[1187:f803] viewDidLoad 
2012-01-31 13:10:26.087 DrinkMixer[1187:f803] viewWillAppear 
2012-01-31 13:10:26.088 DrinkMixer[1187:f803] refreshView 
2012-01-31 13:10:26.089 DrinkMixer[1187:f803] NAME_KEY  = (null) 
2012-01-31 13:10:26.090 DrinkMixer[1187:f803] INGREDIENTS_KEY = (null) 
2012-01-31 13:10:26.090 DrinkMixer[1187:f803] DIRECTIONS_KEY = (null) 
2012-01-31 13:10:26.091 DrinkMixer[1187:f803] nameTextField  = (null) 
2012-01-31 13:10:26.091 DrinkMixer[1187:f803] ingredientsTextView = 
2012-01-31 13:10:26.092 DrinkMixer[1187:f803] directionsTextView = 
2012-01-31 13:10:32.878 DrinkMixer[1187:f803] didSelectRowAtIndexPath...iPad 
2012-01-31 13:10:32.879 DrinkMixer[1187:f803] drinkChanged 
2012-01-31 13:10:32.879 DrinkMixer[1187:f803] refreshView 
2012-01-31 13:10:32.880 DrinkMixer[1187:f803] NAME_KEY  = Blue Dog 
2012-01-31 13:10:32.880 DrinkMixer[1187:f803] INGREDIENTS_KEY = vodka,grapefruit juice 
2012-01-31 13:10:32.881 DrinkMixer[1187:f803] DIRECTIONS_KEY = Combine both while cold. 
2012-01-31 13:10:32.881 DrinkMixer[1187:f803] nameTextField  = (null) 
2012-01-31 13:10:32.882 DrinkMixer[1187:f803] ingredientsTextView = (null) 
2012-01-31 13:10:32.882 DrinkMixer[1187:f803] directionsTextView = (null) 

最後3行中的NSLog在哪裏,我在期待從字典鍵獲取值,而是他們回來(空)。

回答