2011-02-25 96 views
0

我想設置的UIButton的標籤與二維數組 - >如何設置的UIButton的標籤與二維數組

這裏我的代碼,不知道我錯了。


for(int i = 0 ; i<[arrWeekly_Fetch_DataForLandscapeMode count] ; i++) 
{   
    btnLandscape_Button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btnLandscape_Button.backgroundColor = [UIColor clearColor]; 
    btnLandscape_Button.frame = CGRectMake(0,0,200,50); 
    [btnLandscape_Button.titleLabel setFont:[UIFont systemFontOfSize:14]]; 
    btnLandscape_Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 
    [arrCommonDays[1][i] addObject:[arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i]]; 
    [btnLandscape_Button setTag:[1][arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i]]; 
    [btnLandscape_Button addTarget:self action:@selector(btnClick_ForDetailInformation_For_Class_InLandscapeMode:) forControlEvents: UIControlEventTouchUpInside]; 
      [btnLandscape_Button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
      [viewForDisplayData_OnDaily addSubview:btnLandscape_Button]; 

      [btnLandscape_Button setTitle:[dictWeeklyData_InLandscape_Mode objectForKey:@"sSubjectCode"] forState:UIControlStateNormal]; 
     } 
+0

如果你想創建一個網格視圖然後我可以幫助創建這個並添加標籤並訪問每個按鈕,並可以更改每個按鈕的圖像,當你想 – GhostRider 2011-02-25 06:32:58

+0

感謝回覆。你能幫我一樣嗎? – iGW 2011-02-25 09:43:26

回答

0

如果我理解正確你arrWeekly_Fetch_DataForLandscapeMode陣列是2維的(數組的數組),那麼您應該從其中提取的值的下一個方法:

[btnLandscape_Button setTag:[[arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i] objectAtIndex:1]]; 

[btnLandscape_Button setTag:[[arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:1] objectAtIndex:i]]; 

至於你的需求。

+0

感謝回覆首先,但這個答案並沒有幫助我。 arrWeekly_Fetch_DataForLandscapeMode數組是一維的,[arrCommonDays [1] [i]是一個二維數組。 i的值來自[arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i]]和arrCommonDays [1] [i],1對於此循環是靜態的,對於下一個循環,我已經採用了arrCommonDays [2] [i],在這種情況下,i的值是來自[arrtemp objectAtIndex:i]我正在爲每個循環創建按鈕,並且想要爲相同的標籤設置。 [btnLandscape_Button setTag:[1] [arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i]]謝謝 – iGW 2011-02-25 09:30:49

+0

這段代碼是什麼意思setTag:[1] [arrWeekly_Fetch_DataForLandscapeMode objectAtIndex:i] ???我的意思是「[1]」?我從來沒有見過這樣的建築。 – 2011-02-25 12:33:11