UITextView成员变量在我的UIViewController中始终是NIL

时间:2011-07-02 20:46:49

标签: cocoa-touch ios4 interface-builder uitextview

  

可能重复:
  UITextView member variable is always nil in my UIViewController

在我的mib中,我有一个UITextView组件。

在我的UIViewController中,我有一个UITextView成员字段,我使用IB来确保两者是连接的(至少我认为我是通过从“文件所有者”拖动并将其放在IB中的UITextView并选择我的成员变量)。

现在,当我通过setText更新文本时,UITextView仍然是空白的。

当我进入我的代码时,成员变量(称为textView)是NIL。

所以我猜我没有正确使用过IB。如何确保此变量已连接到UITextView图形元素?

这是代码

// My interface looks like

#import <UIKit/UIKit.h>

@interface DetailsController : UIViewController 
{
    UITextView *textView;
}

@property (nonatomic, retain) IBOutlet UITextView *textView; 

@end;


// and the implementation

#import "DetailsController.h"

@implementation DetailsController

@synthesize textView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

// used pressed the "Done" button
- (IBAction)done
{
    [self dismissModalViewControllerAnimated:YES];
}

- (void)setDetails: (NSString *)detail withQuote:(NSString *)quote
{
    NSLog(@"%@", textView);
    [textView setText:detail];
}

@end`

由于 德肖恩

0 个答案:

没有答案