Thanks in advance..
What your interested in is getters and setters. Your controller will
send a setter message to your view with the object. The view saves the
reference as a pointer to the original object. It's still the same
object. There are several ways to do this. It's the same a
NSMutableArray's addObject: method. It takes the pointer reference to
the object and saves it. There is still one copy of the object though
only many pointers to it.
I made a simple example of two ways you can pass the object to your
view and still do what you want without IB. Example is here:
myView.viewPolygon = myPolyObject;
myView1.viewPolygon = myPolyObject;
myView2.viewPolygon = myPolyObject;
--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To post to this group, send email to iphone-appd...@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-aud...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.
The idea behind this is that each object (controller, view, etc) only
knows about it's own reference. You change the ivar in your controller
(basically your model of the MVC) it will propagate to the view.
Things you have to remember is how the setters handle the references.
Is it a retain/release model? Is it a copy/release? Is it an assign
only? These affect if your referencing the same object or a copy. And
wether your guaranteed a valid object no matter where you look or if
it can be released under your nose.
> > iphone-appdev-aud...@googlegroups.com<iphone-appdev-auditors% 2Bunsu...@googlegroups.com>
@end;
The sythesized getters are all the same. each simply returns.
-(PolygonShape *)polygon1 { return polygon1;}
-(PolygonShape *)polygon2 { return polygon2;}
-(PolygonShape *)polygon3 { return polygon3;}
The difference lies where how setters are synthesized, the equivalents
are:
-(void)setPolygon1:(PolyggonShape *value){ polygon1 = value;} //simply
pointer assignment, no retain nor release. polygon1's retain count is
the same,polygon1
// and value points to the same object, update to object pointed
bypolygon1 would update value as well.
-(void)setPolygon2:(PolyggonShape *value)
{
if(polygon2 != value)
{
[polygon2 release];
polygon2 = [value retain]; //polygon2' retain counted
INCREASED by 1
}
}
//polygon2 and value points to the same object, update to object
pointed bypolygon1 would update value as well.
-(void)setPolygon1:(PolyggonShape *value){
if(polygon3 != value){
[polygon3 release];
polygon3 = [value copy]; //polygon3' retain count IS 1,
polygon3 is a new copy,update to polygon3 WOULD NOT AFFECT value.
}
}
Rule of thumb from lecture slides, not sure if it is right.
use assign for primitive types, integer.
use copy for NSString
user retain for others.
Can you please confirm this?
Thanks a great deal