My app crashes, not always, at the following method
// overridden
- (void)dismiss
{
[super dismiss];
[containerView_ removeFromSuperview];
containerView_ = nil;
}
crash happens at removerFromSuperview.
There is a "show" method as well
// overridden
- (void)show
{
if (self.parentView == nil)
{
// No parentView, create transparent view as parent
CGSize frameSize = [UIApplication currentSize];
containerView_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frameSize.height, frameSize.width)];
containerView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
containerView_.backgroundColor = [UIColor clearColor];
self.parentView = containerView_;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if(some condition )
[[UIApplication sharedApplication].keyWindow.subviews.lastObject addSubview:containerView_];
else
[[UIApplication sharedApplication].keyWindow addSubview:containerView_];
}
else
{
[[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:containerView_];
}
}
[super show];
// This is done to allow the Cancel button to be pressed but nothing else - do after [super show]!
self.superview.userInteractionEnabled = YES;
}
It is strange, that code used to work. I am trying to compile the app for arm64, but I don't understand how that modification impacted those methods.
My app is a non-ARC app, and I cannot go to ARC right now.
Any ideas?
Change your code to dismiss view like this.
// overridden
- (void)dismiss
{
if(containerView_)
[containerView_ removeFromSuperview];
containerView_ = nil;
[super dismiss];
}
Please check with below code -
- (void)dismiss
{
if (containerView_)
{
[containerView_ removeFromSuperview];
containerView_ = nil;
[super dismiss];
}
}
Simply check if container view have superview
- (void)dismiss
{
if ([containerView_ superview])
{
[containerView_ removeFromSuperview];
containerView_ = nil;
[super dismiss];
}
}
Related
I got a list of deprecated warning once I updated my xcode to xcode9 and I have no Idea how to fix it
'willRotateToInterfaceOrientation:duration:' is deprecated: first deprecated in iOS 8.0 - Implement viewWillTransitionToSize:withTransitionCoordinator: instead
'willAnimateRotationToInterfaceOrientation:duration:' is deprecated: first deprecated in iOS 8.0 - Implement viewWillTransitionToSize:withTransitionCoordinator: instead
'didRotateFromInterfaceOrientation:' is deprecated: first deprecated in iOS 8.0
'interfaceOrientation' is deprecated: first deprecated in iOS 8.0
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.view addObserver:self forKeyPath:#"bounds" options:NSKeyValueObservingOptionNew context:nil];
if (!_viewFirstAppeared) {
_viewFirstAppeared = YES;
void(^applyViews)(void) = ^{
[self.centerController.view removeFromSuperview];
[self.centerView addSubview:self.centerController.view];
[self doForControllers:^(UIViewController* controller, IIViewDeckSide side) {
[controller.view removeFromSuperview];
[self.referenceView insertSubview:controller.view belowSubview:self.slidingControllerView];
}];
[self setSlidingFrameForOffset:_offset forOrientation:_offsetOrientation];
self.slidingControllerView.hidden = NO;
self.centerView.frame = self.centerViewBounds;
self.centerController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.centerController.view.frame = self.centerView.bounds;
[self doForControllers:^(UIViewController* controller, IIViewDeckSide side) {
controller.view.frame = self.sideViewBounds;
controller.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}];
[self applyShadowToSlidingViewAnimated:NO];
};
if ([self setSlidingAndReferenceViews]) {
applyViews();
applyViews = nil;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
if (applyViews) applyViews();
[self setSlidingFrameForOffset:_offset forOrientation:_offsetOrientation];
[self hideAppropriateSideViews];
});
[self addPanners];
if ([self isSideClosed:IIViewDeckLeftSide] && [self isSideClosed:IIViewDeckRightSide] && [self isSideClosed:IIViewDeckTopSide] && [self isSideClosed:IIViewDeckBottomSide])
[self centerViewVisible];
else
[self centerViewHidden];
}
else if (_willAppearShouldArrangeViewsAfterRotation != UIDeviceOrientationUnknown) {
for (NSString* key in [self.view.layer animationKeys]) {
[self.view.layer animationForKey:key].duration);
}
[self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
[self willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:0];
[self didRotateFromInterfaceOrientation:_willAppearShouldArrangeViewsAfterRotation];
}
[self.centerController viewWillAppear:animated];
[self transitionAppearanceFrom:0 to:1 animated:animated];
_viewAppeared = 1;
}
I was just searching for the same exact thing and found something in iOS documentation and after reading it and since I have users who still have iOS 8. I kept the old two function and add the new one to it.
// old ones
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self handleInterfaceOrientation];
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self handleInterfaceOrientation];
}
// the new method
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
// what ever you want to prepare
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
[self handleInterfaceOrientation];
}];
}
- (void)handleInterfaceOrientation {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
// Landscape
} else {
// Portrait
}
}
In my app I've to create a custom alert view like the following:
So I followed this tutorial to create a custom alert view. I finished it but I'm getting issue in the following method:
- (void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove {
NSMutableArray *items = [[NSMutableArray alloc]init];
[items addObject:self.buttonOk];
[items addObject:self.buttonClose];
int buttonIndex = (tag == 1);
if (shouldRemove) {
[items removeObjectAtIndex:buttonIndex];
} else {
if (tag == 1) {
[items insertObject:self.buttonOk atIndex:buttonIndex];
} else {
[items insertObject:self.buttonClose atIndex:buttonIndex];
}
}
}
I edited it than the tutorial because I don't need a UIToolBar for buttons. When I run the app it says me that I can't insert a nil object in an NSMutableArray, but I don't understand what's wrong, I hope you can help me to fix this issue.
UPDATE
Here's all the class code I developed:
#import "CustomAlertViewController.h"
#define ANIMATION_DURATION 0.25
#interface CustomAlertViewController ()
- (IBAction)buttonOk:(UIButton *)sender;
- (IBAction)buttonCancel:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIButton *buttonClose;
#property (weak, nonatomic) IBOutlet UIButton *buttonOk;
#property (strong, nonatomic) IBOutlet UIView *viewAlert;
-(void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove;
#end
#implementation CustomAlertViewController
- (id)init
{
self = [super init];
if (self) {
[self.viewAlert setFrame:CGRectMake(self.labelAlertView.frame.origin.x,
self.labelAlertView.frame.origin.y,
self.labelAlertView.frame.size.width,
self.viewAlert.frame.size.height)];
[self.buttonOk setTag:1];
[self.buttonClose setTag:0];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)showCustomAlertInView:(UIView *)targetView withMessage:(NSString *)message {
CGFloat statusBarOffset;
if (![[UIApplication sharedApplication] isStatusBarHidden]) {
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
if (statusBarSize.width < statusBarSize.height) {
statusBarOffset = statusBarSize.width;
} else {
statusBarOffset = statusBarSize.height;
}
} else {
statusBarOffset = 0.0;
}
CGFloat width, height, offsetX, offsetY;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
width = targetView.frame.size.width;
height = targetView.frame.size.height;
offsetX = 0.0;
offsetY = -statusBarOffset;
}
[self.view setFrame:CGRectMake(targetView.frame.origin.x, targetView.frame.origin.y, width, height)];
[self.view setFrame:CGRectOffset(self.view.frame, offsetX, offsetY)];
[targetView addSubview:self.view];
[self.viewAlert setFrame:CGRectMake(0.0, -self.viewAlert.frame.size.height, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.viewAlert setFrame:CGRectMake(0.0, 0.0, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView commitAnimations];
[self.labelAlertView setText:#"CIAO"];
}
- (void)removeCustomAlertFromView {
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.viewAlert setFrame:CGRectMake(0.0, -self.viewAlert.frame.size.height, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView commitAnimations];
[self.view performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
}
- (void)removeCustomAlertFromViewInstantly {
[self.view removeFromSuperview];
}
- (BOOL)isOkayButtonRemoved {
if (self.buttonOk == nil) {
return YES;
} else {
return NO;
}
}
- (BOOL)isCancelButtonRemoved {
if (self.buttonClose == nil) {
return YES;
} else {
return NO;
}
}
- (void)removeOkayButton:(BOOL)shouldRemove {
if ([self isOkayButtonRemoved] != shouldRemove) {
[self addOrRemoveButtonWithTag:1 andActionToPerform:shouldRemove];
}
}
- (void)removeCancelButton:(BOOL)shouldRemove {
if ([self isCancelButtonRemoved] != shouldRemove) {
[self addOrRemoveButtonWithTag:0 andActionToPerform:shouldRemove];
}
}
- (void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove {
NSMutableArray *items = [[NSMutableArray alloc]init];
[items addObject:self.buttonOk];
[items addObject:self.buttonClose];
int buttonIndex = (tag == 1);
if (shouldRemove) {
[items removeObjectAtIndex:buttonIndex];
} else {
if (tag == 1) {
[items insertObject:self.buttonOk atIndex:buttonIndex];
} else {
[items insertObject:self.buttonClose atIndex:buttonIndex];
}
}
}
- (IBAction)buttonOk:(UIButton *)sender {
[self.delegate customAlertOk];
}
- (IBAction)buttonCancel:(UIButton *)sender {
[self.delegate customAlertCancel];
}
#end
UPDATE 2
Code in which I use the CustomAlertView:
#import "PromotionsViewController.h"
#import "CustomAlertViewController.h"
#interface PromotionsViewController () <CustomAlertViewControllerDelegate> {
BOOL isDeletingItem;
}
#property(nonatomic,strong) CustomAlertViewController *customAlert;
- (IBAction)buttonBack:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIButton *buttonAlert;
- (IBAction)buttonAlert:(UIButton *)sender;
#end
#implementation PromotionsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.buttonAlert setTitle:self.promotionSelected forState:UIControlStateNormal];
[self.customAlert setDelegate:self];
isDeletingItem = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonBack:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc]init];
[self.customAlert removeOkayButton:NO];
[self.customAlert removeCancelButton:NO];
NSString *message = [NSString stringWithFormat:#"La tua offerta %# del 20%% è stata convertita in punti IoSi x10", self.promotionSelected];
[self.customAlert showCustomAlertInView:self.view withMessage:message];
isDeletingItem = YES;
}
- (void)customAlertOk {
if (isDeletingItem) {
[self.customAlert removeCustomAlertFromViewInstantly];
} else {
[self.customAlert removeCustomAlertFromView];
}
}
- (void)customAlertCancel {
[self.customAlert removeCustomAlertFromView];
if (isDeletingItem) {
isDeletingItem = NO;
}
}
#end
Maybe you're calling addOrRemoveButtonWithTag:andActionToPerform: at a time where your UI is not fully created, since UI elements are created asynchronously. So if you call this method, right after custom alert view instanciation, you'll get your crash because the buttons in the view are not created.
To solve this issue, you need to call addOrRemoveButtonWithTag:andActionToPerform: only once your custom alert has been added to the view hierarchy.
EDIT :
With the example code you gave in edit 2, you call these lines :
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc]init];
[self.customAlert removeOkayButton:NO];
[self.customAlert removeCancelButton:NO];
}
but when you have just instantiated CustomAlertViewController, its 2 buttons are not yet created, so I suggest you add 2 properties hasOkButton and hasCancelButton and a new constructor to your custom class like this one :
- (instancetype) initWithOk:(BOOL)OkButton AndCancel:(BOOL) CancelButton
{
if(self = [super init])
{
hasOkButton = OkButton;
hasCancelButton = CancelButton;
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// At this time, the custom UI buttons will be created in the UI view hierarchy
[self removeOkayButton: hasOkButton];
[self removeOkayButton: hasCancelButton];
}
And in the caller you can use the following to display a custom alert View:
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc] initWithOk:NO AndCancel:NO];
// ...
}
EDIT #2
I tried your solution in a real project, I made it work by using these lines int the caller :
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [self.storyboard instantiateViewControllerWithIdentifier:#"customAlertView"];
self.customAlert.hasOK = NO;
self.customAlert.hasCancel = YES;
NSString *message = [NSString stringWithFormat:#"La tua offerta %# del 20%% è stata convertita in punti IoSi x10", self.promotionSelected];
[self.customAlert showCustomAlertInView:self.view withMessage:message];
isDeletingItem = YES;
}
In the CustomAlertViewController declare 2 visible properties hasOK and hasCancel in.h.
And modify your .m by adding method :
-(void)viewWillAppear:(BOOL)animated
{
[self removeOkayButton:self.hasOK];
[self removeCancelButton:self.hasCancel];
}
Be sure to modify your storyboard (if eligible) to have the "customAlertView" defined this way :
Don't forget also to bind your UIButton to the controller this can be a mistake too in your implementation :
Hope this will help you :)
I found on the web a tutorial to create custom alert view by using code, if you are interested you can go to this tutorial. I used it for my issue and it worked great! You have to fix a few things, because it uses deprecated command but it's easy to fix it.
If you are interested just take a look about this tutorial. I think you can integrate it in your app and after you can easily use for other stuff if it's necessary. I hope that my answer will help someone.
I have a problem with an app that won't set frames outside -init and -viewWillLayoutSubviews methods. What should happen when one taps the editButton is an animation that will hide the editor view. Nonetheless, nothing happens as I test it. The problem doesn't come from the animation method since the -setFrame method as it - not included in the block - doesn't work neither.
Here is the code :
-(id)init {
if (self = [super init]) {
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editButtonTapped)];
doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneButtonTapped)];
editor = [[UIView alloc] init];
[editor setBackgroundColor:[UIColor yellowColor]];
editor.clipsToBounds = YES;
editorIsOpen = YES;
portraitRegularModeEditorRect = CGRectMake(15, 59, 738, 100);
portraitClosedEditorEditorRect = CGRectMake(15, 59, 738, 0);
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:editor];
[[self view] setBackgroundColor:[UIColor blueColor]];
}
-(void)viewDidAppear:(BOOL)animated {
[self setForRegularMode];
}
-(void)viewWillLayoutSubviews {
UIInterfaceOrientation io = [[UIApplication sharedApplication] statusBarOrientation];
if (io == UIInterfaceOrientationPortrait || io == UIInterfaceOrientationPortraitUpsideDown) {
//portrait
[editor setFrame:portraitRegularModeEditorRect];
} else {
//landscape
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)editButtonTapped {
[self setForScenarioLinesEditingMode];
}
-(void)doneButtonTapped {
[self setForRegularMode];
}
-(void)setForRegularMode {
editingMode = CPRegularMode;
if (!editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitRegularModeEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = YES;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:editButton,nil]];
}
-(void)setForScenarioLinesEditingMode {
editingMode = CPScenarioLinesEditingMode;
if (editorIsOpen) {
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^(void){
[editor setFrame:portraitClosedEditorEditorRect];
} completion:^(BOOL finished) {
editorIsOpen = NO;
}];
}
[[self navigationItem] setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneButton,nil]];
}
If anyone can help, thanks in advance ;)
I think that the problem in your case is the fact that in -(void)viewWillLayoutSubviews method you set, lets say the default frame of your view, if you try to change the frame in other methods after the setFrame is called on your view, the -(void)viewWillLayoutSubviews will also be called and the frame of the view will be the default one. Try to remove the setFrame from your -(void)viewWillLayoutSubviews.
Is your view controller set up in storyboards, and are you using Autolayout (which is on by default?) If so, setFrame won't work and you need to edit constraints after creating outlets to them from the storyboard.
Alternatively, you can turn off Autolayout in your storyboard, as shown here.
This is amongst the oddest issues with iOS development I have ever seen. I'm relatively new to iOS development, so I apologize if I'm missing something obvious or my terminology isn't completely correct. If you need clarification, please let me know in the comments and I'll edit my question accordingly.
The Problem
I'm using Three20, so that might have something to do with it. But I have a "Home view" which is basically a series of images that link out to other views (shown in the image below). If I start our in portrait view, all is well.
The next view is a table view, shown below:
YAY! I can rotate and all is right with the world. BUT if I go back to that home view, rotate to landscape, and THEN go to this tabled view, the world breaks.
You'll see that there's a random space added to the right side of my table now. I don't know where and how it came from. Here's my Controller.m file:
#import "FriendTabsController.h"
#import "MyAppApp.h"
#import "JohnDoeManager.h"
#implementation FriendTabsController
#synthesize innerView, segmentedControl, innerController, friendsController, friendRequestsController;
- (void)addBottomGutter:(UIViewController*)controller {
if ([controller isKindOfClass:[TTTableViewController class]]) {
TTTableViewController* tableViewController = (TTTableViewController*)controller;
tableViewController.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,50+44,0);
tableViewController.tableView.contentInset = UIEdgeInsetsMake(0,0,50+44,0);
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Friends";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
friendsController = [[FriendsController alloc] init];
friendRequestsController = [[FriendsController alloc] init];
((FriendsController*)friendRequestsController).friendRequests = YES;
[self addBottomGutter:friendsController];
[self addBottomGutter:friendRequestsController];
innerController = friendsController;
[innerView addSubview:innerController.view];
[innerController viewDidLoad];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
[self loadBannerAd:(orientation)];
}
-(void) loadBannerAd:(UIInterfaceOrientation)orientation{
MainLayer *mi = [MainLayer getInstance];
if (mi.useJohnDoeAds) {
[[JohnDoeManager sharedInstance] setCurrentViewController:self];
[mi.JohnDoeBanner.view removeFromSuperview];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// This is a portait ad
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 410-44, 320, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake(0, 1024-44-90-20, 768, 90)];
}
} else {
// Landscape
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 320-44-58, 410, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake((1024-768)/2, 768-44-90-20, 768, 90)];
}
}
[self.view addSubview:mi.JohnDoeBanner.view];
[mi.JohnDoeBanner rollOver];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self loadBannerAd:(toInterfaceOrientation)];
}
- (IBAction)didChangeSegment:(UISegmentedControl *)control {
if (innerController) {
[innerController viewWillDisappear:NO];
[innerController.view removeFromSuperview];
[innerController viewDidDisappear:NO];
}
switch (control.selectedSegmentIndex) {
case 0:
innerController = friendsController;
self.title = #"Friends";
break;
case 1:
innerController = friendRequestsController;
self.title = #"Requests";
break;
}
[innerController viewWillAppear:NO];
[innerView addSubview:innerController.view];
[innerController viewDidAppear:NO];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[innerController viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[innerController viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[innerController viewWillDisappear:animated];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[innerController viewDidDisappear:animated];
[super viewDidDisappear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[friendsController release], friendsController = nil;
[friendRequestsController release], friendRequestsController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end
So can someone please tell me what's going on? HELP!
You need to set wantsFullScreenLayout property to YES.
in your init methods set
self.wantsFullScreenLayout = YES;
This will solve your problem.
I'm encountering this error with the iOS 3.0 simulator, but not on the 3.1.3 and 3.2 simulators.
After creating a symbolic breakpoint on malloc_error_break, I'm seeing this in the log:
[Session started at 2010-02-13 19:15:22 +0700.]
2010-02-13 19:15:24.405 iPortals[21656:207] bool for 1
iPortals(21656,0xa0089500) malloc: *** error for object 0x285e000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
iPortals(21656,0xa0089500) malloc: *** error for object 0x2850000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
iPortals(21656,0xa0089500) malloc: *** error for object 0x286c000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
iPortals(21656,0xa0089500) malloc: *** error for object 0x287c000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
here is my code
#implementation WebViewController
#synthesize myWebView;
#synthesize AppDelegate;
#synthesize mybanner;
#synthesize request;
- (void)dealloc
{
//NSLog(#"WebViewController has been dealloc");
myWebView.delegate = nil;
self.myWebView = nil;
[self.myWebView release];
[super setView:nil];
[myWebView release];
myWebView = nil;
request = nil;
[mybanner release];
[super dealloc];
}
- (void)setView:(UIView *)aView
{
//NSLog(#"setView:(UIView *)aView");
if (aView == nil) {
self.myWebView = nil;
}
[super setView:aView];
}
- (void)action {
AppDelegate = nil;
AppDelegate = [[UIApplication sharedApplication] delegate];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:AppDelegate.PushLink]];
}
- (void)didReceiveMemoryWarning {
//NSLog(#"didReceiveMemoryWarning: view = %#, superview = %#", [self valueForKey:#"_view"], [[self valueForKey:#"_view"] superview]);
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//NSLog(#"viewDidLoad: view = %#", self.view);
self.title = NSLocalizedString(#"iPortals", #"");
//UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:#"Item" style:UIBarButtonItemStyleBordered target:self action:#selector(action];
//self.navigationController.toolbar setItems: = [[UIBarButtonItem alloc] initWithTitle:#"[...]" style:UIBarButtonItemStyleBordered target:self action:#selector(action)];
/*
UIBarButtonItem *emailButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"icon.png"]
style:UIBarButtonItemStylePlain target:self
action:#selector(action)];
self.toolbarItems = [NSArray arrayWithObjects:emailButton, nil];
[emailButton release];
//*/
AppDelegate = nil;
AppDelegate = [[UIApplication sharedApplication] delegate];
//NSLog(#"777777777 %#",AppDelegate.PushLink);
/*
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y += kTopMargin + 5.0; // leave from the URL input field and its label
webFrame.size.height = 400;
//webFrame.size.height -= 40.0;
self.myWebView = nil;
//*/
//self.myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
self.myWebView.backgroundColor = [UIColor grayColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
self.mybanner.backgroundColor = [UIColor clearColor];
[self.view addSubview: self.mybanner];
/*
CGRect textFieldFrame = CGRectMake(kLeftMargin, kTweenMargin,
self.view.bounds.size.width - (kLeftMargin * 2.0), kTextFieldHeight);
UITextField *urlField = [[UITextField alloc] initWithFrame:textFieldFrame];
urlField.borderStyle = UITextBorderStyleBezel;
urlField.textColor = [UIColor blackColor];
urlField.delegate = self;
urlField.placeholder = #"<enter a URL>";
urlField.text = AppDelegate.PushLink;
urlField.backgroundColor = [UIColor whiteColor];
urlField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
urlField.returnKeyType = UIReturnKeyGo;
urlField.keyboardType = UIKeyboardTypeURL; // this makes the keyboard more friendly for typing URLs
urlField.autocapitalizationType = UITextAutocapitalizationTypeNone; // don't capitalize
urlField.autocorrectionType = UITextAutocorrectionTypeNo; // we don't like autocompletion while typing
urlField.clearButtonMode = UITextFieldViewModeAlways;
[urlField setAccessibilityLabel:NSLocalizedString(#"URLTextField", #"")];
[self.view addSubview:urlField];
[urlField release];
*/
request = nil;
request = [NSURLRequest requestWithURL:[NSURL URLWithString:AppDelegate.PushLink]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[self.myWebView loadRequest:request];
}
// called after the view controller's view is released and set to nil.
// For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc.
// So release any properties that are loaded in viewDidLoad or can be recreated lazily.
//
- (void)viewDidUnload
{
[super viewDidUnload];
// release and set to nil
[self.myWebView release];
self.myWebView = nil;
}
-(BOOL)canBecomeFirstResponder {
//NSLog(#"canBecomeFirstResponder ");
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
//NSLog(#"viewDidAppear ");
[self becomeFirstResponder];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
//NSLog(#"overrideoverrideoverrideoverrideoverrideoverrideoverrideoverride ");
if ( event.subtype == UIEventSubtypeMotionShake )
{
// Put in code here to handle shake
AppDelegate = nil;
AppDelegate = [[UIApplication sharedApplication] delegate];
[AppDelegate ToggleNavigationBar];
[AppDelegate playsound:1];
[self setAdHide:AppDelegate.toggle];
}
}
- (void)setAdHide:(BOOL)hide {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.6];
if (!hide) {
if (current == UIInterfaceOrientationLandscapeLeft || current == UIInterfaceOrientationLandscapeRight) {
[mybanner setFrame:CGRectMake(0, 272, mybanner.frame.size.width, mybanner.frame.size.height)];
}
else {
[mybanner setFrame:CGRectMake(0, 432, mybanner.frame.size.width, mybanner.frame.size.height)];
}
}
else {
[self restoreAd];
}
[UIView commitAnimations];
}
- (void)restoreAd {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.6];
[mybanner setFrame:CGRectMake(0, 0, mybanner.frame.size.width, mybanner.frame.size.height)];
[UIView commitAnimations];
}
#pragma mark -
#pragma mark UIViewController delegate methods
- (void)viewWillAppear:(BOOL)animated
{
self.myWebView.delegate = nil;
self.myWebView.delegate = self; // setup the delegate as the web view is shown
}
- (void)viewWillDisappear:(BOOL)animated
{
//[self.myWebView removeFromSuperview];
[self.myWebView stopLoading]; // in case the web view is still loading its content
self.myWebView.delegate = nil; // disconnect the delegate as the webview is hidden
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
current = interfaceOrientation;
[self restoreAd];
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIDeviceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
// this helps dismiss the keyboard when the "Done" button is clicked
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];
return YES;
}
#pragma mark -
#pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
//NSString* errorString = [NSString stringWithFormat:
// #"<html><center><font size=+5 color='red'>An error occurred:<br>%#</font></center></html>",
// error.localizedDescription];
//[self.myWebView loadHTMLString:errorString baseURL:nil];
//URLCacheAlertWithError(error);
}
#end
Follow the recommendation in the log message: set a breakpoint in malloc_error_break. When the breakpoint fires, look at the backtrace in Xcode (or use the bt command on the gdb command-line) and see where you're calling free, or API that uses free.
Memory use issues are sometimes discoverable using the Xcode static analyzer - choose "Build and Analyze" from the Xcode build menu.
You seem to be repeatedly trying to dealloc your pointers. In the dealloc method ONLY call [blah release]; and in the viewDidUnload method assign your pointers a nil value. Do not do BOTH in both methods.
- (void)dealloc
{
[self.myWebView release];
[mybanner release];
[super dealloc];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.myWebView = nil;
}
You seem to be missing a few variables as well.
This may seem completely unrelated, but with a similar error, what worked for me was to repair the disk permissions.
Open Disk Utility app -> Repair Disk Permissions
Restart the computer
I got this suggestion from Mac Terminal - 'pointer being freed was not allocated' error when opening terminal
Also, I realize that the question is 6 years old, so it's unlikely to be useful to the original asker. I hope this answer helps other people with similar errors.
Amazingly, what solved it for me was to shut down and turn back on the debug device. Oh, Apple...