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 05-27-2011, 09:55 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default Hard to fix Zombie

Hi all... I'm working on an iPad (universal) app that is giving me some trouble. We have a kind of "floating" window that has a close button on the side. Its contents are gathered from a UIViewController instance that have a couple UITextFields on a tableview. The issue comes up when doing multiple touches around on the screen, and the user happens to close the Window during some delegate calls that sometimes get delayed by the system (tableview datasource and delegate calls, textfield delegate calls).
Most of the issues went away when I carefully set the delegates and datasources to nil on the view controller's dealloc method. But one of them persists: if I try to close the window and simultaneously try to begin editing a text field, I get a message sent to deallocated instance
Code:
*** -[ViewController respondsToSelector:]: message sent to deallocated instance 0x4240ba0
And this is the call stack :
Code:
#0  0x34d4f910 in ___forwarding___ ()
#1  0x34d4f860 in __forwarding_prep_0___ ()
#2  0x300d6ae4 in -[UITextField canBecomeFirstResponder] ()
#3  0x30032ce8 in -[UIResponder becomeFirstResponder] ()
#4  0x300d69cc in -[UITextInteractionAssistant setFirstResponderIfNecessary] ()
#5  0x300d642c in -[UITextInteractionAssistant oneFingerTap:] ()
#6  0x34d44bbe in -[NSObject(NSObject) performSelector:withObject:] ()
#7  0x300c63d2 in -[UIGestureRecognizer _updateGestureWithEvent:] ()
#8  0x300c618a in -[UIGestureRecognizer _delayedUpdateGesture] ()
#9  0x3002d7b0 in _UIGestureRecognizerUpdateObserver ()
#10 0x300451de in _UIGestureRecognizerUpdateGesturesFromSendEvent ()
#11 0x30044fe0 in -[UIWindow _sendGesturesForEvent:] ()
#12 0x30044c0a in -[UIWindow sendEvent:] ()
#13 0x3002ffc6 in -[UIApplication sendEvent:] ()
It seems the system is trying to make the field become first responder, but while it does its thing my dealloc method is reached and the field itself is gone.

Any clue as to what can be done to avoid this ?
It happens when I touch the close button slightly before touching the textField. If I do the opposite, it won't crash.

Thank you
Rafael
nobre84 is offline   Reply With Quote
Old 05-27-2011, 10:38 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Hmm im not sure what i would do with that.

From what you have suggested it would require the user to push 2 "buttons" (term used lightly) at the same time - in this case the edit and close buttons?

Couldnt you just move them further apart so that the user would struggle to push them both at the same time? Or as soon as the close button is touched have it lock out the rest of the UI so that nothing on that view can be used until it is reloaded. that way once the close has been pushed the user cant push anything else to cause the exception.

Doesnt really get rid of the problem, but should get around it.

Not elegant but my 2 cents :P

p.s. i know not a push - a Touch
Meredi86 is offline   Reply With Quote
Old 05-27-2011, 12:39 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

Thanks for the tip, I'll give it a try setting userInteractions disabled for the content view when tapping the close button, I don't know if it will react fast enough to prevent tho.
nobre84 is offline   Reply With Quote
Old 05-27-2011, 01:02 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 140
MatthewD is on a distinguished road
Default

Could you show some code?

Sounds like if you were to nil your pointer after releasing it, you wouldn't have the crash.
MatthewD is offline   Reply With Quote
Old 05-27-2011, 03:29 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

I had this on the VIew Controller's dealloc, that holds a tableView with a UITextField on each of its cells:
Code:
[tableView release];
As "self" was the delegate for the textfields, closing the container window while doing something on the fields (or scrolling the table) had they call a method on the now dead controller
I added these :
Code:
//table
    tableView.delegate = nil;
    tableView.dataSource = nil;
//active textfield
if ([currentControl respondsToSelector:@selector(setDelegate:)]) {
        [currentControl setDelegate:nil];
}
This solved the problem for the table and any in-editing text field, but not when activating a previously untouched text field. (only the active text field is having its delegate set to nil).
I then changed the approach, setting the textField delegates to nil on the custom UITableViewCell dealloc method, thus all textfields now have a nil delegate when the Parent view controller is released, but its still crashing :/

Trying to block interactions when clicking the close button didn't work when dealing with multiple, almost instantaneous touches
nobre84 is offline   Reply With Quote
Old 05-27-2011, 03:41 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

The tableviewcell's dealloc is too late to set the delegates to nil, I tried a couple logs in there and the View controller is long gone when the system cleans up the cells, its dealloc is reached by a long stack starting with "delayedPerformCleanup ()" that goes reclaiming all UIViews and removing each one from its superviews.
I'll try to hold pointers to each of them on a collection and do this cleanup straight from the VC's dealloc.
nobre84 is offline   Reply With Quote
Reply

Bookmarks

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: 337
6 members and 331 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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