2012-07-11 48 views
0

我有兩個UIViews。一個名爲SelectText的UIView具有NSMutableArray的伊娃,其在執行特定功能後填充。NSMutableArray從另一個視圖返回空

這裏是一個代碼段的代碼:

- (void)fillDrawPoints 
    { 
     //the codes.... 
    [self.drawnPoints addObject:[NSValue valueWithCGPoint:currPoint]]; 
    } 

注:drawnPoints陣列在SelectText的initWithFrame初始化。另外,我總是通過在函數中添加一個日誌來檢查數組是否實際填充到視圖中。

現在我想要做的就是從另一個視圖訪問這個數組。這是我做的:

TextView.h

#import "SelectText.h" 

@interface TextView : UIView 
{ 
    SelectText *txtSel; 
} 

@property (nonatomic, retain) SelectText *txtSel; 

TextView.m

@synthesize txtSel; 

- (void)getDrawingPoints:(NSMutableArray *)pointArray 
{ 
    self.pointArray = pointArray; 
    NSLog(@"Array count: %d", [self.pointArray count]); 
} 

正如你可以從上面的代碼中看到的,我想傳遞數據內部txtSel.drawnPointstextView.pointArray供以後使用。問題是,當我嘗試從另一個視圖訪問它時,txtSel.drawnPoints總是返回空白。我在這裏做錯了什麼?

補充:

我這是怎麼instatiate SelectText

- (id)initWithFrame:(CGRect)frame 
    { 
     self = [super initWithFrame:frame]; 
     if (self) { 
     txtSel = [[SelectText alloc]init]; 
     [self addSubView:txtSel]; 

     //rest of code... 
    } 
+0

訪問SelectText類的所有屬性是否確實txtSel被正確設置,而不是簡單的零?如果你嘗試從nil獲得一個屬性,Objective-C在運行時不會抱怨。 – 2012-07-11 03:47:06

+0

要加入@ctrahey的觀點,試着懶洋洋地實例化txtSel。 – tarheel 2012-07-11 04:44:09

+0

你提到你在viewDidLoad中初始化了SelectPoint的drawPoints:SelectText。然而,SelectText是一個沒有-viewDidLoad的UIView:被覆蓋。 – 2012-07-11 06:01:41

回答

0

變化的TextView類init方法如下

- (id)initWithClassSelectText:(SelectText *)selectText { 
    if ((self = [super init])) { 
     txtSel = selectText; 
    } 
    return self; 
} 

而且當你的TextView的實例,您使用此:

TextView textView = [[TextView alloc] initWithClassSelectText:self]; 

現在你可以使用txtSel對象

相關問題