可可:不能从另一个类获得属性值?

时间:2012-06-12 10:56:13

标签: cocoa-touch

我的CustomClass1中有一个属性: @property(assign)NSString * url;

- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener{
_url= [[request URL] absoluteString] ;
NSLog(@"requested url is %@",_url);
NSInteger index=[_tabView numberOfTabViewItems];
NSTabViewItem *newItem=[[NSTabViewItem alloc] init];
[_tabView insertTabViewItem:newItem atIndex:index];
[newItem setLabel:@"Empty Tab" ];
//[_tabView  selectPreviousTabViewItem:@"select"];
[self initializeWebView:newItem];
[[_tabView .tabViewItems objectAtIndex:index] setView:[newVC view]];
 // NSLog(@"requested url is %@",url);

}

-(void)awakeFromNib{

CustomClass1 *obj=[[CustomClass1 alloc] init];
NSLog(@"url is %@",[obj url]);
[[_newWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:obj.url]]];

}

如何在Viewcontroller类的awakefromnib方法中获取_url的值? NSlog返回null。 我该如何解决这个问题? 请帮帮我

1 个答案:

答案 0 :(得分:0)

您的“url”属性需要先分配并初始化为某些内容,然后才能返回“nil”以外的内容。

您可以在“url”对象的“init”方法中设置“CustomClass1”属性的内容,但这样做有一点诀窍({{ 3}})。