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
.
精彩评论