简体   繁体   中英

How do I populate a NSMutableArray with UILabels?

I don't think I am creating this array of UILabels correctly.

If I put a breakpoint after this line of code, it shows that the array is empty.

 colorLabelArray = [[NSMutableArray alloc] initWithObjects:  greenLabel, orangeLabel, blackLabel,purpleLabel, yellowLabel, redLabel, blueLabel, whiteLabel, nil];

If I do the same thing with UIImages it works just fine. What am I missing?

Are you certain that none of the label objects are nil? Specifically, if greenLabel is nil, then initWithObjects: will ignore the rest of the argument list and return an empty array.

Your syntax is fine. I would check if greenLabel is nil?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM