Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-14-2010, 01:15 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Question Accessing a variable in drawRect

I'm trying to access an array that is passed into my view class when it is initialized.

In the initWithFrame it is passed in as follows

Code:
- (id)initWithFram:(CGRect)frame eventsArray:(NSMutableArray *)array {
if (self = [super initWithFrame:frame]) {
eventsArray = array;
}
return self;
}
The events array is defined and synthesized and I've tested it and at that point it has been passed in correctly and exists.

If I try to reference it from drawRect it is just an empty array. Can you not reference things from drawRect? I originally tried to build the array from the drawRect, but it also threw an error trying to access the managed object context.
__________________
Shablabla
kgodard is offline   Reply With Quote
Old 01-14-2010, 01:47 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

I see you're not retaining the array you get - is it possible that the original array is autoreleased, or gets released or otherwise emptied by code in the original caller?

If you NSLog(@"%@:", eventsArray) in that init method, is the eventsArray ok there?
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-14-2010, 01:53 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
I see you're not retaining the array you get - is it possible that the original array is autoreleased, or gets released or otherwise emptied by code in the original caller?

If you NSLog(@"%@:", eventsArray) in that init method, is the eventsArray ok there?
I tried adding retain to the eventsArray and the eventsArray in the caller and it didn't change.

I am using NSLog to check and yes it is the correct information in the init method.
__________________
Shablabla
kgodard is offline   Reply With Quote
Old 01-14-2010, 03:26 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

If it's not a retain issue, you could try logging the *address* of the array in the init and again in the drawRect.

NSLog(@"%d", eventsArray)

If the address changes, then someone is changing the value of eventsArray somewhere. If the address does not change but the contents do, then someone else has a pointer to the array you're passing in is removing the contents.
__________________

Free Games!

Last edited by smasher; 01-14-2010 at 03:40 PM.
smasher is offline   Reply With Quote
Old 01-14-2010, 05:53 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 26
kgodard is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
If it's not a retain issue, you could try logging the *address* of the array in the init and again in the drawRect.

NSLog(@"%d", eventsArray)

If the address changes, then someone is changing the value of eventsArray somewhere. If the address does not change but the contents do, then someone else has a pointer to the array you're passing in is removing the contents.
The address is normal in init and is 0 in drawRect. I think I'm going to do it differently and create the array in init rather than passing it in.
__________________
Shablabla
kgodard is offline   Reply With Quote
Old 01-14-2010, 08:18 PM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by kgodard View Post
The address is normal in init and is 0 in drawRect. I think I'm going to do it differently and create the array in init rather than passing it in.
Strange - if the address changes to 0, then either someone is doing eventsArray=nil or you're dealing with a different object. You could try logging the address of "self" to see if it's the same object.

Could also be a buffer overrun somewhere, but that's much less likely.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
drawrect, init, variable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 334
9 members and 325 guests
2Apps1Day, akacaj, Domele, michelle, NSString, SLIC, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:02 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0