2011-02-15 83 views
0

我是有myclass.m 4個陣列問題正從一個級陣列到另一個類

我需要得到這些陣列到myclassviewcontroller.m

對於我像myclassviewcontroller.m編寫代碼這個。

- (void)resultarrays :(NSMutableArray *)Agentids loanofficerid:(NSMutableArray *)Loanofficerid agentname:(NSMutableArray *)agentname agentemail:(NSMutableArray *)agentemail agentphone:(NSMutableArray *)Agentphone { 

    agentids = [[NSMutableArray alloc] initWithObjects:Agentids,nil]; 
    loanofficerid = [[NSMutableArray alloc] initWithObjects:Loanofficerid,nil]; 
    agentnames = [[NSMutableArray alloc] initWithObjects:agentname,nil]; 
    agentemails = [[NSMutableArray alloc] initWithObjects:agentemail,nil]; 
    agentphone = [[NSMutableArray alloc] initWithObjects:Agentphone,nil]; 

    NSLog(@"123 %@",agentids); 
    NSLog(@"123 %@",loanofficerid); 
    NSLog(@"123 %@",agentnames); 
    NSLog(@"123 %@",agentphone); 
} 

在myclass.m我寫這篇文章

myclassviewcontroller *LOVobj = [[myclassviewcontroller alloc]init]; 
    [LOVobj resultarrays:resultData_agent loanofficerid:array1 agentname:array2 agentemail:array3 agentphone:array4]; 

然後它會顯示我在控制檯打印的所有對象。

在此之後,在按鈕單擊我打印這些數組,然後它打印空。

即使我給它分配setter和getter方法。

我沒有什麼問題可以任何人請幫助我。

謝謝你提前。

+0

查看按鈕單擊後打印的代碼會很有幫助。 – Bogatyr 2011-02-15 10:33:14

回答

0

首先,代碼改成這樣:

- (void)resultarrays :(NSArray *)Agentids loanofficerid:(NSArray *)Loanofficerid agentname:(NSArray *)agentname agentemail:(NSArray *)agentemail agentphone:(NSArray *)Agentphone { 

    agentids = [[NSMutableArray alloc] initWithArray: Agentids]; 
    loanofficerid = [[NSMutableArray alloc] initWithArray: Loanofficerid]; 
    agentnames = [[NSMutableArray alloc] initWithArray: agentname]; 
    agentemails = [[NSMutableArray alloc] initWithArray: agentemail]; 
    agentphone = [[NSMutableArray alloc] initWithArray: Agentphone]; 

    NSLog(@"123 %@",agentids); 
    NSLog(@"123 %@",loanofficerid); 
    NSLog(@"123 %@",agentnames); 
    NSLog(@"123 %@",agentphone); 
} 

不通過可變數組,如果你不希望它改變。

+0

是的,我改變它,但沒有變化,它在控制檯打印,但如果使用這個數組有顯示null – MaheshBabu 2011-02-15 10:55:21

0

首先,創建的數組包含對數組的引用,而不是參數數組中的對象數組。而且,由於您正在存儲參數數組的引用,所以如果參數數組的內容發生更改,那麼所有引用都會更改。

你可能不是想這樣的事對於每個陣列:

agentids = [NSMutableArray arrayWithArray: Agentids]; 

(和[agentids保留]因爲arrayWithArray返回一個自動釋放的對象)。

+0

謝謝你的回答Bogatyr,但沒有變化 – MaheshBabu 2011-02-15 10:52:50