This is the behavior of iPhoto.
Using the code below the second NavBar appears but then I get EXC_BAD_ACCESS.
The results are the same if I uncomment the final line of code to removeFromSuperview
I am stuck. Can you please tell me what I am missing?
Many Thanks, Mark
- (void)touchesEnded

NSSet *)touches withEvent

UIEvent *)event {
UITouch *theTouch = [touches anyObject];
/*
If this is a single tap, and the NavBar is visible ,then disappears
*/
if ([theTouch tapCount] == 1) {
NSTimer* aTimer = [NSTimer scheduledTimerWithTimeInterval: 4.0f target:self
selector:@selector(theTimer

userInfo:nil repeats: NO];
[self setNavBar: [[UINavigationBar alloc]
initWithFrame:CGRectMake (0, 0, self.frame.size.width, 44)]];
[[self navBar] setTranslucent:YES];
[[self navBar] setBarStyle:UIBarStyleBlack];
[self setNavItem: [[UINavigationItem alloc] initWithTitle:[photo name]]];
[navBar pushNavigationItem:navItem animated:YES];
[self addSubview:navBar];
[navItem release];
[navBar release];
NSLog(@"Hello from touchesEnded:withEvent:");
}
}
- (void) theTimer: (NSTimer *) timer
{
[timer invalidate];
[timer release];
//[navBar removeFromSuperview];
}
///////
(gdb) break malloc_error_break
Breakpoint 18 at 0x9063c072
(gdb) po aTimer
<NSCFTimer: 0x5b6a2c0>
(gdb) continue
2010-04-09 14:11:36.426 iHungryMePlus-iPad[3167:207] Hello from touchesEnded:withEvent:
(gdb) po timer
<NSCFTimer: 0x5b6a2c0>
(gdb) p(int)[timer retainCount]
$1 = 3
(gdb) p(int)[navBar retainCount]
$2 = 2
(gdb) p(int)[navItem retainCount]
$3 = 2
(gdb) continue
Program received signal: “EXC_BAD_ACCESS”.
(gdb)
Debugger shows
"asm objc_msgSend 0x9191fec0"
Thread-1 -<com.apple.main.thread>
#0 0x9191fed7 in objc_msgSend
#1 0xbfffea2c in ??
#2 0x02b4b943 in CFRunLoopRunSpecific
#3 0x02b4b048 in CFRunLoopRunInMode
#4 0x0315589d in GSEventRunModal
#5 0x03155962 in GSEventRun
#6 0x002f3de1 in UIApplicationMain
#7 0x00002698 in main at main.m:13