Friday, 15 August 2014

objective c - Add contents of an IBoutletcollection to an array? -



objective c - Add contents of an IBoutletcollection to an array? -

i have 2 iboutletcollections called numbers , symbols. want add together contents of title in array such first element of array numbers , sec symbols, 3rd numbers, 4th symbols , on. there way it?

edit:

//@property (strong, nonatomic) iboutletcollection(uibutton) nsarray symbols; //@property (strong, nonatomic) iboutletcollection(uibutton) nsarray *numbers; -(void)setnumbers:(nsarray *)numbers { _numbers=numbers; (uibutton button in self.numbers) { number * number = [[number alloc]init]; [button settitle:[number randnum] forstate:uicontrolstatenormal]; } }

this code setting title of outlet collection numbers.

here go, assuming iboutletcollections contain elements of class uilabel , have same number of elements:

@property (strong, nonatomic) iboutletcollection(uibutton) nsarray *numbers; @property (strong, nonatomic) iboutletcollection(uibutton) nsarray *symbols; nsmutablearray *result = [[nsmutablearray alloc] initwithcapacity:self.numbers.count+self.symbols.count]; (int = 0; < self.numbers.count+self.symbols.count; i++) { if (i%2 == 0) { [result addobject:((uibutton *)self.numbers[i]).titlelabel.text]; } else{ [result addobject:((uibutton *)self.symbols[i]).titlelabel.text]; } }

the solution problem run loop , in loop modulo calculation 2 find out when have or odd position in result array, , add together element appropriate iboutletcollection. clear?

objective-c arrays iboutletcollection

No comments:

Post a Comment