"Normal" UIButton that calls obj_stack_overflow or EXC_BAD_ACCESS exception

He sure looks harmless enough. In my delet delegate I check NSUserDefaults, to show the flag hints at startup. If it is set then, at the end of applicationDidFinishLaunching: , I do this:

 TipsViewController *vc = [[TipsViewController alloc] initWithNibName:@"TipsView" bundle:nil]; [window addSubview:vc.view]; [vc release]; ] TipsViewController *vc = [[TipsViewController alloc] initWithNibName:@"TipsView" bundle:nil]; [window addSubview:vc.view]; [vc release]; 

The idea is to temporarily show this opinion. (Note that this is not a modal VC. There is no navigation controller at this point, plus theres no navigation bar in this view anyway.)

Once this idea is rejected, we add preview of UITabBarController window and navigate to it, and then delete the submission tips from the main window. I have not reached the point of holding the point of view, because, well, read on.

My TipsViews VC is connected more or less like this:

 UIView -> view -> File's Owner (TipsViewController) UIImageView -> background image UIView -> tipView -> File's Owner UIImageView -> background image UIScrollView UILabel (tip text) UIButton -> touch-up-inside -> -(IBAction)button1: UIButton -> touch-up-inside -> -(IBAction)button2: UIButton -> touch-up-inside -> -(IBAction)button3: 

Source contains the declarations and definitions for all three calls IBAction. Now two of them are doing nothing. The third changes the tip text , resize and customize views scroll contentSize to match.

When I run the application, presentation TipsViewController displayed just fine. I can even scroll through the help text. However, when I run the touch-up-inside on any UIButton, Xcode begins to put me into the source (where Ive put a breakpoint at each IBAction) ... and then output via EXC_BAD_ACCESS or obj_stack_overflow .

I compared this to other parts of the application where I have a VC, view and buttons. It is identical in every way, except that in this case Ive added the VCs view as a subspecies of the application window instead of pushing the VC on the navigation controller. Moreover, the Guide to program the controller for iPhone OS docs say it's fair game:

If you use one view controller in your application, you add its view to the window instead of adding the view controller to the tab bar or navigation controller.

However, I have UITabBarController, waiting in the wings, and it has a tab with UINavigationControllers (and other VC). However, if a tooltip view is displayed, the tab view controllers view has not yet been added to the window. The goal is to change it, after the tips have been made. In other words, in all senses and purposes, they temporarily acted as if we had one VC in the game. After that, we switch to the tab bar and reset the VC tip.

Maybe I'm doing something wrong? Is there a better way? ("Theres must be the best way!")

Stack trace example:

 #0 0x992b6f52 in objc_exception_throw #1 0x302d6ffb in -[NSObject doesNotRecognizeSelector:] #2 0x3026e056 in ___forwarding___ #3 0x3024a0a2 in __forwarding_prep_0___ #4 0x308f79d1 in -[UIApplication sendAction:to:from:forEvent:] #5 0x309598b1 in -[UIControl sendAction:to:forEvent:] #6 0x3095bad2 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] #7 0x3095a81e in -[UIControl touchesEnded:withEvent:] #8 0x30910fdf in -[UIWindow _sendTouchesForEvent:] #9 0x308faecb in -[UIApplication sendEvent:] #10 0x309013e1 in _UIApplicationHandleEvent #11 0x32046375 in PurpleEventCallback #12 0x30245560 in CFRunLoopRunSpecific #13 0x30244628 in CFRunLoopRunInMode #14 0x32044c31 in GSEventRunModal #15 0x32044cf6 in GSEventRun #16 0x309021ee in UIApplicationMain #17 0x00002888 in main at main.m:14 : from: forEvent:] #0 0x992b6f52 in objc_exception_throw #1 0x302d6ffb in -[NSObject doesNotRecognizeSelector:] #2 0x3026e056 in ___forwarding___ #3 0x3024a0a2 in __forwarding_prep_0___ #4 0x308f79d1 in -[UIApplication sendAction:to:from:forEvent:] #5 0x309598b1 in -[UIControl sendAction:to:forEvent:] #6 0x3095bad2 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] #7 0x3095a81e in -[UIControl touchesEnded:withEvent:] #8 0x30910fdf in -[UIWindow _sendTouchesForEvent:] #9 0x308faecb in -[UIApplication sendEvent:] #10 0x309013e1 in _UIApplicationHandleEvent #11 0x32046375 in PurpleEventCallback #12 0x30245560 in CFRunLoopRunSpecific #13 0x30244628 in CFRunLoopRunInMode #14 0x32044c31 in GSEventRunModal #15 0x32044cf6 in GSEventRun #16 0x309021ee in UIApplicationMain #17 0x00002888 in main at main.m:14 

As you can see from the road, we end up on doesNotRecognizeSelector: ... except for the fact that I can clearly see the methods in the original source VC. In addition, they are all connected. (There are no several kinds of connections or anything similar in IB. Everything looks good there, right down to the relationship with file owners.)

Keys are welcome / appreciated!

+4
source share
1 answer

The problem is your first piece of code: you instantiate the TipsViewController, retaining its view, and then free the view controller, which will free it. So now target key is a pointer to the unallocated view controller.

The presentation is not saved his view controller, and they do not retain their delegates or goals.

You need to keep a saved copy of the view controller may have in the property retain , until you want to view displays. When you finish viewing, you can remove it from the parent view and release the view controller.

+8
source

All Articles