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
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
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
I've created a view with a logout button and I'm trying to make that a subview of another view. The logout button view has a xib and a controller associated with the xib.
How do I make it so that this view/controller is a part of my other view?
The way I've done this before is by having a view that draws itself programmatically, drawing that view in the interface builder as part of another view and changing the class for that view. As I want that view to respond to methods, I made it have a protocol and then made the controller it was a subview of implement that.
Is that the only way to do it? Or is there a way such that I have an independent controller for my logout view that I can just 'drop in' into other views, because the drawback of the other method is that every view that wants to use this subview has to implement the protocol, even if that method is going to be the same in every view.
Create a superclass to abstract the logout behavior. Then, each UIViewController that supports the logout should subclass that superclass. In the superclass, provide the method for logout.
This approach will enable you to either simply hook up UIControls in Interface Builder to the common IBAction in the superclass, or alternatively, even add specific customization in the subclass before invoking the superclass method.
Here's one possible example:
LogoutViewController.h
#import <UIKit/UIKit.h>
#interface LogoutViewController : UIViewController
-(void)performLogout;
#end
LogoutViewController.m
#import "LogoutViewController.h"
#interface LogoutViewController ()
#end
#implementation LogoutViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)performLogout
{
//do logout code
}
- (IBAction)logout:(id)sender
{
[self performLogout];
}
#end
SomeOtherViewController.h
#import <UIKit/UIKit.h>
#import "LogoutViewController.h"
#interface SomeOtherViewController : LogoutViewController
#end
SomeOtherViewController.m
#import "SomeOtherViewController.h"
#implementation SomeOtherViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)mySpecificLogoutButtonPressed:(id)sender
{
self.title = #"Good bye";
// do other code specific to logging out from this UIVC
[super performLogout];
}
#end
You can use NSNotificationCenter for this. So you can post the notification on logout button action. You can check the documentation.
Hope this helps.
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.
I'm quite new at iOS development and I'm facing some trouble with hiding/showing button in my GUI. Because I need some buttons to appear or disappear and to be enabled or disabled. I followed some great tutorials over the net but can not figure out what is going wrong with my code.
Here is my ViewController.h :
/
// ViewController.h
// WeddingVideoBooth
//
// Created by Frédéric Mouza on 15/07/13.
// Copyright (c) 2013 Frédéric Mouza. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UIButton *but_record;
}
#property (nonatomic,retain) IBOutlet UIButton *but_record;
- (IBAction)but_record:(UIButton *)sender;
#end
and my .m file :
//
// ViewController.m
// WeddingVideoBooth
//
// Created by Frédéric Mouza on 15/07/13.
// Copyright (c) 2013 Frédéric Mouza. All rights reserved.
//
#import "ViewController.h"
#import "MobileCoreServices/UTCoreTypes.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize but_record;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
but_record.hidden=YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)but_record:(UIButton *)sender {
but_record.enabled=NO;
}
#end
It's very simple and, to understand, I just would like the button to disable when you click on it... Currently, the button remains the same when you click on it. I also tried to hide it using the property "but_record.hidden=YES" but nothing worked.
Does somebody have an idea, please ?
Thanks again
Add an NSLog() into your but_record to see if the IBAction is actually getting called. It sounds like that is not triggering as you probably didn't link them together in your Interface Builder. And as mentioned above take out the hidden=YES
Ok, just to wrap-up and properly close the question.
It's probably obvious for most of you but when dealing with interface one has to be careful:
if you create a button, link it to the interface, give it properties... and then you copy it Xcode keeps the previous link in the copy and if you create a new link by control+drag in your .h file, the previous link remains and may supersede the new one.
Therefore, to prevent this, you have to remove the existing links from the link tab after you copied a button but before you create a new link.
That worked for me.
Hope this will help,
Fred