Iphone UIView parent method call
I'm stuck with an issue.... Please help!
I have a navigation controller project. From the root controller I am pushing a view onto the stack that has some info and 2 buttons (YES, NO). (it can't be an AlertView). If they press the YES button, I call a method on the parent view (using a delegate method) and pop the view from the stack. The method on the parent pushes a new view onto the stack. I assumed the parent method would remain in memory after the deallocation of the child view because the method exists on the parent, but when the child is deallocated it also deallocates everything created inside the method on the parent. Does anyone have a solution for responding to events that happen on a child view in a parent view that will remain after the child is deallocated?
Thanks!
in header file:
#import <UIKit/UIKit.h>
@protocol decrementDelegate;
@interface decrement : UIViewController {
int currentCount;
IBOutlet UILabel *countLabel;
id <decrementDelegate> delegate;
}
@property (nonatomic, assign) id <decrementDelegate> delegate;
@end
@protocol decrementDelegate <NSObject>
-(void)decrementControllerDidFinish:(decrement *)controller
withString:(NSString *)stringValue;
@end
in implementation file:
[self.delegate decrementControllerDidFinish:self
withString:countLabel.text];
[self.navigationController popViewControllerAnimated:YES];
caller:
-(void)decrementControllerDidFinish:(decrement *)controller
withString:(NSString *)stringValue {
// Show our details
myNewChildController *viewController = [[myNewChildController alloc]
initWithNibName:@"myNewChildController" bundle:nil];
viewController.delegate = self;
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
Using non-delegate and just calling a method on the parent:
caller:
mySummary *parent = [self.navigationController.viewControllers objectAtIndex:0];
[mySummary setMyAllowOnParent:@"Allowed"];
[self.navigationController popViewControllerAnimated:YES];
parent:
-(void)setMyAllowOnParent:(NSString *)aAllow {
newView *viewController = [[newView alloc] initWithNibName:@"newView" bundle:nil];
[self.navigationController 开发者_运维技巧pushViewController:viewController animated:YES];
[viewController release];
}
newView crashes with deallocated error when caller view is deallocated. Does anyone have an idea how to resolve this issue?
How did you create your delegate? You didn't accidentally used retain instead of assign (assuming you use a property to access it)? Because if you used retain, this might have caused the issue.
By the way, you mention something about a UIAlertView that cannot be used, which leads me to think that you created a view with a similar design as a UIAlertView. Perhaps the following link might be useful:
how can i make popup login window similar as on istore in objective-C/cocoa-touch
精彩评论