我的接缝简单,但我无法让它工作。 我有一个变量进入ViewController(由模态视图显示),在viewController中我访问appDelelgate以获取传递的NSArray中的变量。在我分配它之前,我可以验证变量是否可用于我的NSLog,所以我知道它就在那里。 在.h文件中如下;
@class ViolinMakerAppDelegate;
@interface DetailsViewController : UIViewController
{
ViolinMakerAppDelegate *dappDelegate;
DetailsViewController *detailsView;
IBOutlet UIViewController *modalViewController;
IBOutlet UITextView *violinMakerDescription;
}
@property (retain, nonatomic) ViolinMakerAppDelegate *dappDelegate;
@property (nonatomic, retain) DetailsViewController *detailsView;
@property(nonatomic, assign) UIViewController *modalViewController;
@property (nonatomic, retain) IBOutlet UITextView *violinMakerDescription;
在.m文件中如下。
#import "DetailsViewController.h"
#import "ViolinMakerAppDelegate.h"
@implementation DetailsViewController
@synthesize detailsView, violinMakerDescription, dappDelegate;
- (void)viewWillAppear:(BOOL)animated
{
dappDelegate = (ViolinMakerAppDelegate *) [[UIApplication sharedApplication] delegate];
DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:@"DetailsViewController" bundle:nil];
self.detailsView = detailsViewController;
// Tried below, but the variable is not getting to the IBOutlet..
NSString *aviolinMakerDescription = [dappDelegate.violinMakers description];
[self.detailsView.violinMakerDescription setText:aviolinMakerDescription];
NSLog(@"violinMakerDescription: %@", [dappDelegate.violinMakers description]);
// tried -----> [self.detailsView.violinMakerDescription setText:[dappDelegate.violinMakers description]];
}
我确信这很简单,因为我知道变量'description'有我想要的东西。我只是继续得到IB中的静态文本。我确信我已经将IB连接正确,因为我从RootViewController推送另一个视图的工作方式类似,并且所有连接都相同且非常简单。一个IB插座,一个UITextView。
这对我来说听起来很疯狂,但有没有理由因为这个视图处于模态视图中,它无法将变量加载到文本字段中,只能从模态控制器将变量发送回程序?
那里的任何人都喜欢帮助我通过我的密集头骨通过这个最终代码将其分配给IBOutlet? 提前致谢, 柯克
@Scott 我已经尝试了一切,并认为这是需要的......不确定。 这是我从另一个视图以模态方式呈现DetailsViewController的地方,由根控制器推送。
case 0:
{
DetailsViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
UINavigationController *aDetailsViewController = [[UINavigationController alloc] initWithRootViewController:detailsViewController];
self.detailsView = detailsViewController;
// °°°[self.view addSubview:detailsViewController.view];
// self.violinMakerView = violinMakerViewController;
// [[self navigationController] pushViewController:detailsViewController animated:YES];
dappDelegate = (ViolinMakerAppDelegate *) [[UIApplication sharedApplication] delegate];
// This does show the variable is loaded here too.
NSLog(@"violinMakerDescription from Details Segment: %@", [dappDelegate.violinMakers description]);
// attempting to load it here as well rem out doesn't change things
[violinMakerDescription setText:[dappDelegate.violinMakers description]];
// NSLog(@"violinMakerDescription loaded in segment Segment: %@", violinMakerDescription);
[self presentModalViewController:aDetailsViewController animated:YES];
[violinMakerView release];
[detailsViewController release];
[aDetailsViewController release];
break;
我真的不知道我在上面文本中的DetailsViewController中需要什么来让它加载变量....我希望它对你有意义。感谢您提供的帮助或有所帮助的任何内容!
答案 0 :(得分:1)
在你的实现中,DetailsViewController是视图的模态控制器吗?如果是这样,我不明白是否需要以下代码:
DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:@"DetailsViewController" bundle:nil];
self.detailsView = detailsViewController;
您似乎正在加载另一个视图并在其中分配描述,并且从不在同一视图中显示它。我不知道你是如何为模型视图加载代码的,所以看来你可以在viewWillAppear中尝试以下代码:(BOOL):
[violinMakerDescription setText:[dappDelegate.violinMakers description]];
这将设置您当前视图的描述,除非我遗漏了某些内容,否则应该是您所需要的。