簡體   English   中英

無法從數組檢索uilabel

[英]cannot retrieve uilabel from an array

我有一個UILabels數組,但無法從數組中使用該UILabel。 下面是我的代碼

for (int b=0; b<ObjIQuestions.m_muteArrOptions.count; b++)
        {

           UILabel* Optionlabel=[[UILabel alloc]initWithFrame:CGRectMake(LabelXaxis, 0, (FrameWidth/ObjIQuestions.m_muteArrOptions.count), 50)];
            IstructOptions *ObjOptions=[ObjIQuestions.m_muteArrOptions objectAtIndex:b];
            Optionlabel.text=ObjOptions.m_strNameEn;
            Optionlabel.numberOfLines=0;
            NSString* cleanedQnString = [appdelegate.HomePageStyle.m_strTopbarColor stringByReplacingOccurrencesOfString:@"#" withString:@""];
            //Optionlabel.textColor=[self colorWithHexString:@"F75454"];
            Optionlabel.textColor=[self colorWithHexString:cleanedQnString];
            Optionlabel.font=[UIFont fontWithName:@"Verdana" size:12];
            Optionlabel.textAlignment=UITextAlignmentCenter;
            LabelXaxis=LabelXaxis+(FrameWidth/ObjIQuestions.m_muteArrOptions.count);
            [self.m_ArrQnOptionLabels addObject:Optionlabel];
        }

我的數組不為空。 但是我無法使用以下代碼檢索UILable實例。AddSubView無法正常工作。 optionlabel獲取一個UILabel。

UILabel* Optionlabel=(UILabel *)[self.m_ArrQnOptionLabels objectAtIndex:0];
[cell.m_CtrlViewCompartment addSubview:Optionlabel];

該代碼應該可以正常工作,希望您可能不會初始化self.m_ArrQnOptionLabels

分配並初始化Array:

self.m_ArrQnOptionLabels  = [[NSMutableArray alloc]init]; // before using it

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM