I know there are many questions like this. I read all. My problem is very simple.
I created a single view app from xcode file>new project>single view app.
Then i added a second uiviewcontroller in storyboard and a new viewcontroller class named secondViewController. I dragged a button to main viewcontroller and by ctrl+drag to secondViewController on storyboard. I did the reverse in secondViewController. And just added dealloc functins with nslog to class files. I also added weak references to uibuttons
Dealloc method of each viewcontroller never gets called when view changes.
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"viewDidLoad 1");
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
NSLog(#"dealloc 1");
}
SeconViewController.m
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
NSLog(#"dealloc 2");
}
#end
ARC is enabled.
Zombies seem to be disabled on product>edit scheme. I am using xcode 6.2. In instruments allocation screen memory rises at each toggle.
What is the problem, I couldnt find?
dealloc calls when object's (Here its viewcontroller object) swipe out from memory.But here in your case you must presenting view controllers from one another that leads to call only viewwilldisappear and diddisappear.
In storyboard if you want to remove those view controllers completely from memory u should call unwind segue
Related
in my ViewController I have a barButton, and I created a listener for it as shown in the code posted below.
at run time, when I click the barButton the log message in the bar button Action method onBarButtonPressed doe snot display.
please let me know how to create an action listener for the bar button?
code
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a
nib.
[self collectValues];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onBarButtonPressed:(id)sender {
NSLog(#"CLICKED");
}
- (void) collectValues {
self.textFieldValueToDispatch;
}
#end
image
Check the sent actions in the connection inspector . You have triggered a segue on bar button in your screen shot
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I'm not sure what I changed or how to fix these errors:
Cannot find interface declaration for 'ViewController';
View controller cannot use 'super because it is not a root class
Likely you forgot to sub-class UIViewController (check your header):
#interface ViewController : UIViewController
i want to call a method "shows()" but why i am getting the error that "expected identifier or ( " and "use of undeclared identifier self"
ViewController.m
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
NSDictionary *inventory;
}
- (void)shows;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shows
{
NSLog(#"%#",inventory);
}
[self shows];
#end
You can't call [view shows]; in the class scope, you need to call it within a method, like in viewDidLoad
Call it like this:
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
[self shows];//SHOWS call moved here...
}
You can't call this method outside. You can call it inside of anyother method. Like you can call this method in ViewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
[self shows];
}
You have to place the code in another method, it can't be left in the open by it self.
Put it in your viewDidLoad: method or elsewhere
I code with Xcode v6.1.1
I have two classes: Reports, and Admin.
When we are in Reports (first view), I tap on admin button, and the Admin view appears (second view).
When I tap on exit button (in Admin view), I would like that Admin view disappears and Reports comes back.
I don't know if I make error in code, but NSLog appears from prepareForUnwind.
Unwind segue appears in storyboard and link to "exit". Unwind segue identifier : "unwindToContainerVC" Action : prepareForUnwind:
Here is my code :
Admin.h:
#import <UIKit/UIKit.h>
#import "Reports.h"
#interface Admin : UIViewController
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue;
#end
Admin.m:
#import "Admin.h"
#interface Admin ()
#end
#implementation Admin
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
NSLog(#"Called unwind action");
}
#end
Have I to put something in Reports.h or Reports.m ?
Thanks !
Did you wire up the Exit Button to the "exit" action in your storyboard?
Make sure you followed all of the instructions here: Using Unwind Segues
simple codes..
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)dragout:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)dragout:(id)sender {
NSLog(#"-----");
}
#end
and in Storyboard, there is 1 button which size is fit in text "button". Link 'sent event:touch drag outside" to "dragout" IBAction.
When I touch button inside and drag my finger to outside of button, i need move more than button size to call "dragout" IBAction. Nearly 3x width&height size. Why is this happens? Thx for read.