objective c - Xcode: How do I put this into a loop? -


i new xcode , trying make code more efficient. have code below , want put repeated lines @ end loop (there many more items in array). sure it's simple can't figure out how evaluate variables within loop. asking google wrong question isn't helping!

glossarydetailviewcontroller *dcontroller = segue.destinationviewcontroller; glossarydict = glossaryarray [indexpath.row]; dcontroller.detaillabeltext = [glossarydict objectforkey:@"explanation"]; dcontroller.detailtitle = [glossarydict objectforkey:@"term"]; nsmutablearray *labelarray; labelarray = [glossarydict objectforkey:@"label"]; dcontroller.labelstring0 = labelarray[0]; dcontroller.labelstring1 = labelarray[1]; 

i know how create loop ie for(int i=0;i

any pointers appreciated. thanks!

if asking how automate these :

dcontroller.labelstring0 = labelarray[0]; dcontroller.labelstring1 = labelarray[1]; dcontroller.labelstringxx=labelarray[xx]; 

then have 2 ways:

either use arrays individual properties of glossarydetailviewcontroller

for(nsinteger i=1; i<labelarray.count; i++){     dcontroller.labelstring[i]=labelarray[i]; } 

or, use key value coding (if restricted not change class):

for (nsinteger i=1; ;i++) { //still here need put 1      nsstring *propertyname=[nsstring stringwithformat:@"labelstring%d",i];     if([dcontroller respondstoselector:nsselectorfromstring(propertyname)]){         [dcontroller setvalue:labelarray[i] forkey:propertyname];     }     else break; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -