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 12-16-2011, 06:25 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 10
mikesowerbutts is on a distinguished road
Angry UIControl is being used after its been destroyed

Hi,

I have a pretty major problem, basically i have a XIB which I am loading in, which contains a number of UIControls. I programatically add some UITextFields to the view of the UIViewController which loads the XIB. I then "close" the view, which deallocs the owning UIViewControler, then re-launch it and when i interact with the UITextFields on the view, theyre pointing to the OLD UITextFields, not the ones i just created when i re-launched the view.

This is causing me a pretty major problem in that I have drag/drop controls which can be added to the UITextFields and on the "drop" of the draggable object on the UITextField, the dropped object is being added to the OLD UITextField, not the one I just created in the viewDidLoad.

I have been working on this for ages now and I am really stumped.

Could the UIViewController's view be being cached somehow and the UITextFields along with it?

I have done a check to see if any UITextFields exist in the viewDidLoad by:
Code:
int cnt = 0;
for(int i = 0; i < [self.view.subviews count]; i++){
    if([[self.view.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
        cnt++
}
and the cnt var is always 0...

I just don't understand why the old UITextFields are receiving the events?

In my UIViewController's dealloc method, i release each of the UITextFields, but when i run the app "normally" i.e. not debugging through XCode, the app crashes in the dealloc. When debugging, this crash doesn't occur and the NEW UITextFields do receive the dropped object, but I cant fathom as to why its crashing in dealloc when its run normally, but not when debugging? The object's retainCount should be the same in either scenario...

Any suggestions appreciated.

Mike
mikesowerbutts is offline   Reply With Quote
Old 12-16-2011, 06:51 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mikesowerbutts View Post
Hi,

I have a pretty major problem, basically i have a XIB which I am loading in, which contains a number of UIControls. I programatically add some UITextFields to the view of the UIViewController which loads the XIB. I then "close" the view, which deallocs the owning UIViewControler, then re-launch it and when i interact with the UITextFields on the view, theyre pointing to the OLD UITextFields, not the ones i just created when i re-launched the view.

This is causing me a pretty major problem in that I have drag/drop controls which can be added to the UITextFields and on the "drop" of the draggable object on the UITextField, the dropped object is being added to the OLD UITextField, not the one I just created in the viewDidLoad.

I have been working on this for ages now and I am really stumped.

Could the UIViewController's view be being cached somehow and the UITextFields along with it?

I have done a check to see if any UITextFields exist in the viewDidLoad by:
Code:
int cnt = 0;
for(int i = 0; i < [self.view.subviews count]; i++){
    if([[self.view.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
        cnt++
}
and the cnt var is always 0...

I just don't understand why the old UITextFields are receiving the events?

In my UIViewController's dealloc method, i release each of the UITextFields, but when i run the app "normally" i.e. not debugging through XCode, the app crashes in the dealloc. When debugging, this crash doesn't occur and the NEW UITextFields do receive the dropped object, but I cant fathom as to why its crashing in dealloc when its run normally, but not when debugging? The object's retainCount should be the same in either scenario...

Any suggestions appreciated.

Mike
Post the code that creates and add the text fields and other controls. Also post the dealloc method for your view controller.

Add a log statement or breakpoint to the dealloc method of your view controller to make sure your view controller is actually getting deallocated.

My guess is that the view controller is sticking around and not getting deallocated. So the next time around, it still has contents in it's view.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 12-16-2011, 07:01 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

How do you create and show the vc/xib ? Through a navigation controller ?
Are you sure you VC gets dealloc'd ? What do you mean by they point at the old text edits ? Where your draggable objects come from ? How they know which control they drop into ? You may have left a dangling pointer / delegate to the old VC before it goes away. Any delegates should be set to nil on dealloc
nobre84 is offline   Reply With Quote
Old 12-16-2011, 07:23 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 10
mikesowerbutts is on a distinguished road
Default

Hi,

the dealloc is definately getting called as I have already been breakpointing it and NSLogging in it for the last few days.
Here is a sample of one of the text fields i create in the viewDidLoad method:
Code:
oppDets_Date = [[MHTextField alloc] initWithFrame:CGRectMake(42, 109, 100, 25)];
        self.oppDets_Date.font = [[WSStyle instance] getNormalFont];
        self.oppDets_Date.delegate = self;
        [self.view addSubview:self.oppDets_Date];
        self.oppDets_Date_Controller = [[[WSDateFieldController alloc] initWithFieldAndWSDate:oppDets_Date currentDate:bluesheetDataModel.date] autorelease];
        [oppDets_Date checkFlag:@"1.1"];
I would have put all the code in, but i kept getting an error when trying to submit this post saying there is a 10k char limit

Here is the dealloc:
Code:
- (void)dealloc {
    //Other
    [dragDrop release];
    [acp_Controller release];
    [acpSlider release];
    ///*
    //Fields
    //[oppDets_Date release];
    //[oppDets_Date removeFromSuperview];
    [oppDets_Date_Controller release];
    
    //[oppDets_CloseDate release];
    //[oppDets_CloseDate removeFromSuperview];
	[oppDets_CloseDate_Controller release];
    
    //[oppDets_CurrentVolume release];
	//[oppDets_CurrentVolume removeFromSuperview];
    [oppDets_CurrentVolume_Controller release];
    
    
    //[oppDets_PotentialVolume release];
    //[oppDets_PotentialVolume removeFromSuperview];
	[oppDets_PotentialVolume_Controller release];
    
    //[oppDets_SalesPerson release];
    //[oppDets_SalesPerson removeFromSuperview];
    [oppDets_SalesPerson_Controller release];
    
    //[oppDets_Account release];
    //[oppDets_Account removeFromSuperview];
    [oppDets_Account_Controller release];
    
    //[oppDets_Product release];
    //[oppDets_Product removeFromSuperview];
    [oppDets_Product_Controller release];
    
    //[oppDets_Revenue release];
    //[oppDets_Revenue removeFromSuperview];
	[oppDets_Revenue_Controller release];
    
    //[compSalesFunnel_plInSalesFun release];
    //[compSalesFunnel_plInSalesFun removeFromSuperview];
    [compSalesFunnel_plInSalesFun_Controller release];
    
    //[compSalesFunnel_CompType release];
    //[compSalesFunnel_CompType removeFromSuperview];
    [compSalesFunnel_CompType_Controller release];
    
    //[compSalesFunnel_specComps release];
    //[compSalesFunnel_specComps removeFromSuperview];
	[compSalesFunnel_specComps_Controller release];
    
    //[compSalesFunnel_myPosVsComp release];
    //[compSalesFunnel_myPosVsComp removeFromSuperview];
	[compSalesFunnel_myPosVsComp_Controller release];
    
    //[compSalesFunnel_timeForPri release];
    //[compSalesFunnel_timeForPri removeFromSuperview];
	[compSalesFunnel_timeForPri_Controller release];
    
    //Tables
    /*
     [icp_ICCTable release];
     [icpController release];
     
     [buyInf_Involved release];
     [buyInf_Results release];
     [buyInf_Covered release];
     
     [summ_Strengths release];
     [summ_Strengths_Controller release];
     
     [summ_RedFlags release];
     [summ_RedFlags_Controller release];
     
     [possActions release];
     [possActions_Controller release];
     
     [bestActionPlan release];
     [bestActionPlan_Controller release];
     
     [informationNeeded release];
     [informationNeeded_Controller release];
     */
    [super dealloc];
}
I appreciate that I have many memory leaks in the dealloc - i have commented out some of the releases to stop the app crashing when running "normally" (i.e. not debugging) the dealloc does definately get called. I have been breakpointing and NSLogging in it for a few days now...

The MHTextField objects (which are a subclass of WSTextField, which is subclass of UITextField) initially point their delegate to the UIViewController, in the WSTextFieldController objects they are controlled by, the WSTextField.delegate gets set to the WSTextFieldController and the WSTextFieldController.delegate gets set to the UIViewController which created the MHTextFields.

Also, in response to nobre84:
I create the vc like so:
Code:
BlueSheetViewController *bsViewController = [[[BlueSheetViewController alloc] initWithNibNameAndXML:@"BlueSheetView" bundle:[NSBundle mainBundle] XML:blobDataXml AppletID:[opp GetProp:@"Id"]] autorelease];
and the XIB is loaded like this:
Code:
[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
where super means the BlueSheetViewController's base class UIViewController
Thanks,

Mike

Last edited by mikesowerbutts; 12-16-2011 at 07:30 AM.
mikesowerbutts is offline   Reply With Quote
Reply

Bookmarks

Tags
dealloc, drag and drop, uievents, uitextfield

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: 399
13 members and 386 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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