2010-02-24 33 views
0

我實際上開始放棄生活的意願,這段代碼讓我瘋狂!從數組解析txt到UILabel

我試圖讓mathspractice.txt的內容轉換成* myLabel

我使用數組是:

-(void)loadText 
{ 
    NSArray *wordListArray = [[NSArray alloc] initWithArray: 
    [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@」mathspractice」 ofType:@」txt」] 
    encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@」\n」]]; 
    self.theMathsPractice = wordListArray; 
    [wordListArray release]; 
} 

,然後我試圖把它傳遞到* myLabel

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)]; 
     myLabel.text = *theMathsPractice; 
     [myScrollView addSubview:myLabel]; 
     [myLabel release]; 
     } 

任何人都可以幫忙嗎?

回答

1

它快速檢查看你的theMathsPractice是一個NSArray,而不是NSString,這是你想要分配給標籤的文本屬性。您至少應該將該數組重新格式化爲某種類型的字符串,然後再將其分配給標籤。

(同樣不知道爲什麼你正在使用的assignment--的*解引用它,我認爲這將拋出一個編譯器錯誤,因爲裸非參考Objective-C的對象是不是真的不允許的。)

+0

謝謝本,我明白我現在失蹤了什麼...我會回來!再次感謝 – 2010-02-24 16:41:43

0

我會使用以下內容:

myLable.text = [theMathsPractice componentsJoinedByString:@" "]);