开发者

Int is not the same in the same file. iPhone

开发者 https://www.devze.com 2023-03-20 11:10 出处:网络
I have an iPhone App which has one file (.h .m) for 2 nibs. I have a button on nib1 which adds buttonPressed {

I have an iPhone App which has one file (.h .m) for 2 nibs. I have a button on nib1 which adds

buttonPressed {
number ++;
}

and both nib1 and nib2 are supposed to display this int. But nib2 will only display 0 while nib1 is counting up whe开发者_开发问答n I press the button. If I reverse this and put the button on nib2 then nib1 won't display it. Yet again they share the code for since they both come from the same file. Other methods work fine for both nib1 and nib2. But this int wont count from the other view.


Two nibs make 2 separate objects which do not share the same instance of number. It doesn't matter that they share the same class to represent the objects. If you want to share variables between objects you might want to look into singleton design pattern or try using NSUserDefaults.

0

精彩评论

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

关注公众号