2010-02-27 49 views
1
@property (nonatomic, retain) NSMutableArray *filteredListContent; 
---- 
@synthesize filteredListContent; 


- (void)applicationDidFinishLaunching:(UIApplication *)application {  


    NSMutableArray *test = [[NSMutableArray alloc] init]; 
    [test addObject:@"test string"]; 
    [filteredListContent addObjectsFromArray:test]; 


    NSLog(@"%@", test); 
    NSLog(@"Filtered Array is %@", filteredListContent); 

    [window makeKeyAndVisible]; 
} 

我日誌中的測試顯示「測試字符串」,而是「過濾名單數組(null)的如何設置另一個陣列的數組?

如何設置陣列「filteredListContent」與陣列測試...

我在做什麼錯? :-(

回答

0

你必須實際創建filteredListContent,比如用[[NSMutableArray alloc] init]。你得到的錯誤是你調用一個方法,-addObjectsFromArray:,仍然是零的對象:從不創建。因此,它只是返回零,並且永遠不會過濾列表。

2

您創建和隨時隨地初始化filtersListContent?你的代碼看起來正確,應該工作。

你也應該確保釋放你test變量,你在這裏有內存泄漏。

0

filteredListConte nt是一個指向NSMutableArray的指針,它沒有任何內存分配給它,因此你不能調用它的方法。編譯器不會生成錯誤,因爲您正在向nil傳遞消息,這是完全正確的。

-1

Thanx的。

所以我改了行......

[filteredListContent addObjectsFromArray:test]; 

閱讀...

filteredListContent = [NSMutableArray arrayWithArray:test]; 

這樣做了。我想我現在明白了,儘管我宣佈它,我從來沒有創造它...

Thanx。

+0

什麼爲內存管理問題。查看http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html。 – kennytm 2010-02-27 19:02:46

+0

'$ prevComment =〜s/^ What/Watch /;' – kennytm 2010-02-27 19:48:20

相關問題