Re: Help
Re: Help
- Subject: Re: Help
- From: Graham Cox <email@hidden>
- Date: Thu, 9 Jul 2009 09:57:50 +1000
On 08/07/2009, at 4:44 PM, himanshu jain wrote:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// pointsArray =[[NSMutableArray alloc]init];
NSLog(@"init");
//bounds=frame;
//NSLog(@"%@",frame);
}
return self;
}
-(void)pointsArray:(NSMutableArray*) tempArray
{
pointsArray=tempArray;
NSLog(@"here2:%@",pointsArray);
//for(NSValue *value in pointsArray)
}
-(void)points:(CGPoint)pointArray
{
points=pointArray;
//[pointsArray addObject:points];
}
-(NSMutableArray*)point {
return pointsArray;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
CGRect bounds =[self bounds];
CGContextRef context= UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
//NSLog(@"%@",points);
NSLog(@"polyview:%@",self);
if([ self point]!= NULL)
{
NSLog(@"%@",[self point]); //*PROBLEM IS HERE CAN NOT GET POINTS
ARRAY*
Look again at your -initWithFrame: method. You have commented out the
allocation of pointsArray, so it's nil (as returned by the bizarrely
named 'point' method).
Your memory management is all over place here, or to be more specific,
it's non-existent. For example if something is calling your
'pointsArray:' method, you are simply assigning the tempArray to
pointsArray. That does not take ownership of tempArray so it's likely
that it will get autoreleased out from under you, leaving a stale
pointer which will later crash when accessed. There may be other
problems but it's too hard to read your code easily as it is formatted
here.
Also, do yourself a favour. Don't name the setter for 'pointsArray' as
'pointsArray' and the getter 'point', use the conventions which are
setPointsArray: and pointsArray respectively. This is more than just a
naming convention. Key technologies such as KVC, KVO and bindings rely
on correct naming. By the same token, use 'nil' not NULL for nil
objects.
You need to review much of the basic documentation such as memory
management, accessors and naming.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Help (From: himanshu jain <email@hidden>) |