开发者

Add Custom View when Custom Model is Added

My appDelegate class contains an NSMutableArray called blocks, which is an array of custom block objects.

My viewcontroller class has another NSMutableArray called blockViews, which is an array of custom blockView objects. In its init method, it sets it backgroundcolor to a color passed in the parameter, and does some fancy stuff with the border.

Whenever an object is added to my blocks array, I would like to also add a corresponding object to my blockViews array in my viewcontroller, which shares the same location as the location passed to the block object in the blocks array, and adds itself as a subview to the viewcontroller.view.

I would preferably like to use KVO to check whenever an object is added to the blocks array, and then add an object to the blockViews.

I'm relatively new to objective-c programming, but ho开发者_StackOverflow社区w might someone accomplish this?


Peter Hosey's answer to another question will tell you what you need to know about KVO with NSMutableArray.

In your case, the thing observing the NSMutableArray should be your view controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜