Button click not working in iOS - ios

I am building an ANE which will start a new View which contains a label and button. I was successful in adding view as bundle and view controller in my .a file.
I am starting my view as a subview. And later when I click button, it should do some stuffs and change the label text. I can display the view using below code but my button click event is not working.
--- Code to start view ---
My ViewController class name is 'VideoViewController' and bundle containing xib name is 'ViewBundle.bundle'
UIApplication *app = [UIApplication sharedApplication];
UIViewController *myViewController;
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * pathToMyBundle = [mainBundle pathForResource:#"ViewBundle" ofType:#"bundle"];
NSAssert(pathToMyBundle, #"bundle not found", nil);
NSBundle *bundle = [NSBundle bundleWithPath:pathToMyBundle];
myViewController = [[VideoViewController alloc] initWithNibName:nil bundle:bundle];
[app.keyWindow addSubview:myViewController.view];
--- VideoViewController.h ---
#import <UIKit/UIKit.h>
#interface VideoViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *textLabel;
#property (strong, nonatomic) IBOutlet UIButton *clickBtn;
- (IBAction)BtnTapped:(id)sender;
- (IBAction)BtnTappped:(UIButton *)sender;
#end
--- VideoViewController.m ---
#import "VideoViewController.h"
#interface VideoViewController ()
#end
#implementation VideoViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self logMessage:#"From did load"];
[_clickBtn setUserInteractionEnabled:YES];
[_clickBtn setTitle:#"Click Here" forState:UIControlStateNormal]; // button text changes here
}
#pragma mark - Public
- (IBAction)BtnTapped:(id)sender {
[_textLabel setText:#"Btn Tapped"];
}
- (IBAction)BtnTappped:(UIButton *)sender {
[_textLabel setText:#"Btn Tappped"];
}
#pragma mark - Private
- (void)logMessage:(NSString *)msg {
NSLog(#"%#", msg);
[_textLabel setText:msg];
}
#end
I tried to give touch event programmatically, but still button click event doesn't work.
Can anyone please help to sort out this issue?

Please check your clickButton is on its superView

Issue was with view initialisation. Replace [app.keyWindow addSubview:myViewController.view]; with
[app.keyWindow.rootViewController presentViewController:myViewController animated:false completion:nil]; solved my issue.

Related

Passing back info between delegates on ObjectiveC

I need to pass back an NSMutableArray of photos between a CameraSessionView; how store the photos taken from camera on an NSMutableArray, and a TableViewController how uploads this photos to DropBox. I'm using delegates and protocols, but all the ways I tried... fail.
Anyone can help me. I think Im doing some little thing wrong.
I show you some code:
CameraSessionView.h
#class CameraSessionView;
#protocol CameraSessionViewDelegate <NSObject>
#optional
-(void)uploadPhotosFromCamera:(NSMutableArray*)photos;
#end
#property (nonatomic, weak) id <CameraSessionViewDelegate> delegado;
CameraSessionView.m
#property (nonatomic, strong) NSMutableArray* images;
- (void)onTapOkButton{
NSLog(#"Save photos");
if([self.delegado respondsToSelector:#selector(uploadPhotosFromCamera:)])
[self.delegado uploadPhotosFromCamera:_images];
[self onTapDismissButton];
}
PhotosTableViewController.h
#interface PhotosTableViewController : UITableViewController <CameraSessionViewDelegate>
PhotosTableViewController.m
#property (nonatomic, strong) CameraSessionView *camera;
- (void)viewDidLoad
{
_camera = [CameraSessionView new];
[_camera setDelegado:self];
}
-(void)uploadPhotosFromCamera:(NSMutableArray*)photos
{
NSLog(#"UPFC");
for(int x=0; x < [photos count];x++)
{
NSLog(#"UPFC...");
UIImage *foto = [photos objectAtIndex:x];
if (foto.size.height > 1000 || foto.size.width > 1000)
foto = [self imageWithImage:foto scaledToScale:0.15f];
DBMetadata* datos = [TablaSubidas addFile:pathElemento];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *data = UIImageJPEGRepresentation(foto, 1.0);
[fileManager createFileAtPath:[self photoPath:datos] contents:data attributes:nil];
[elementosTabla insertObject:datos atIndex:0];
}
[self sincFotos];
[self.tableView reloadData];
}
Only wants that when I press OK button the photos send back to PhotosTableViewController where it would be uploaded to dropbox.
self.delegado on onTapOKButton is always nil.
Looks easy but I cant run it.
I'm so grateful if anyone could help me or recommend me any tutorial...
Thanks!!
Your CameraSessionView instance will be released from memory as soon as viewDidLoad ends. You need to store it in a property in PhotosTableViewController so that it is retained.
Your delegate should also be defined as weak, e.g.
#property (nonatomic,weak) id< CameraSessionViewDelegate >delegado;
Then in your implementation of PhotosTableViewController, you'll need to implement the -(void)uploadPhotosFromCamera:(NSMutableArray*)photos; method.
Also as this method is defined as #optional, you should check if the delegate responds to it before calling it.
if([self.delegado respondsToSelector:#selector(uploadPhotosFromCamera:]){
[self.delegado uploadPhotosFromCamera:_images];
}
This will prevent the app from crashing if the delegate method isn't implemented.
This is working for me. So, you can implement this Directly. Hope, you will get success. Oh! first check without camera activity. Just pass simple array of string to test the delegate
/............*****************
CameraSessionView.h file
/............*****************
#import <UIKit/UIKit.h>
#class CameraSessionView;
#protocol CameraSessionViewDelegate <NSObject>
#optional
-(void)uploadPhotosFromCamera:(NSMutableArray*)photos;
#end
#interface CameraSessionView : UIViewController
#property (nonatomic,weak) id< CameraSessionViewDelegate >delegado;
#end
/............*****************
CameraSessionView.m file
/............*****************
#import "CameraSessionView.h"
#interface CameraSessionView ()
#property (nonatomic, strong) NSMutableArray* images;
#end
#implementation CameraSessionView
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(onTapOkButton)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"OK" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}
- (void)onTapOkButton{
NSLog(#"Save photos");
_images = [[NSMutableArray alloc]init];
[_images addObject:#"_images1"];
[_images addObject:#"_images2"];
//NSLog(#"from del:%#",_images);
if([self.delegado respondsToSelector:#selector(uploadPhotosFromCamera:)])
[self.delegado uploadPhotosFromCamera:_images];
[self onTapDismissButton];
}
-(void)onTapDismissButton{
[self.view removeFromSuperview];
}
#end
/............*****************
DetailViewController.m file
/.........********
#import "DetailViewController.h"
#import "CameraSessionView.h"
#interface DetailViewController ()<CameraSessionViewDelegate>
#end
#implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
CameraSessionView *Camara= [[CameraSessionView alloc]initWithNibName:#"CameraSessionView" bundle:nil];
[Camara setDelegado:self];
[self.navigationController pushViewController:Camara animated:YES];
}
-(void)uploadPhotosFromCamera:(NSMutableArray*)photos{
NSLog(#"success:%#",photos);
}
#end
If you have to pass data from B View Controller To A view Controller
Create protocol in B View Controller as
#protocol BViewControllerDelegate <NSObject>
-(void)didclickonSubmit:(NSArray*)selected_array;
#end
Create an id, so that you can assign any class as its delegate class.
#property (weak,nonatomic) id<BViewControllerDelegate> delegate;
Call this method in B View Controller on submit button or wherever required.
if (self.delegate && [self.delegate respondsToSelector:#selector(didclickonSubmit:)])
{
[self.delegate didclickonSubmit:myarray];
}
Create an object of B View Controller in View Controller A and assign A as delegate of B
BViewController *b = [[BViewController alloc]init];
b.delegate=self;
Implement required protocol methods of B in A and access the array
-(void)didclickonSubmit:(NSArray*)array
{
NSArray *myarray =[[NSMutableArray alloc]initWithArray:array];
}
now you can use myarray,as u like it..
hit link for sample project
https://www.dropbox.com/s/002om8efpy6fout/passDataToPreviousContoller.zip
Hope it helps..
****EDITED****
u can for sure assign tableViewController as delegate of UIView class.
#protocol BView <NSObject>
-(void) didclickonSubmit:(NSArray*) selected_array;
#end
#interface BView : UIView
#property (weak,nonatomic) id<BView> delegate;
#end
in A i.e. your tableViewController create an object of B and assign your tableview controller as delegate of B .
BView *b=[[BView alloc]init];
b.delegate=self;
Happy Coding..:)

UILabel is nil- canot update text of UILabel

So this a beginner's question, I have to admit, to you guys, but I really have no idea what I should do ,and it have taken me several hrs to try to fix it.
So: My question is that why the UILabel is nil when I want to update its text?
Details:
1:I have two Views and DetectionView is the initial View where there is a UILabel and a bar button item named "Setting" in the toolbat at the button of this view, and second View is the EnterCommandView where there is a UITextField and a bar button item named "save" in the toolbar at the top of this view.
2: After I enter a String, After the app finish launching, I click Setting, then I segue form first View to second View. In second, I enter some string in the UITextField and then click "Save" button, the second View is dismissed, and then I go back to the Initial View,
3: When I go back to the InitialView, the String just entered should appear in the UILabel, but , right it does not, which is exactly my problem, And then I set a breakpoint at the place where I update the UILabel, I have the info at the end of this post, saying UILabel is nil
Code:
EnterCommnadViewController.h
#import <UIKit/UIKit.h>
#import "RscMgr.h"
#protocol EnterCommandDelegate <NSObject>
#optional
-(void) commandEntered:(NSString*)command;
#end
#interface EnterCommandViewController : UIViewController <RscMgrDelegate,EnterCommandDelegate>
{
RscMgr* rscMgr;
IBOutlet UITextField *inputTextField;
}
-(void)sendMessage:(NSString*)message;
-(id)initWithDelegate:(id)delegateToBe;
- (IBAction)cancelPressed;
- (IBAction)savePressed;
#property (nonatomic,weak) id<EnterCommandDelegate> delegate;
#end
EnterCommandViewController.m
#import "EnterCommandViewController.h"
#import "DetectionViewController.h"
#interface EnterCommandViewController () <UITextFieldDelegate>
{
#private
BOOL connected;
}
#end
#implementation EnterCommandViewController
#synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
[inputTextField becomeFirstResponder];
}
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
inputTextField.delegate = self;
}
-(void) viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
inputTextField.delegate = nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)cancelPressed {
[self dismissViewControllerAnimated:YES completion:^{}];
}
- (IBAction)savePressed {
if([[[UIDevice currentDevice]systemVersion] compare:#"7.0" options:NSNumericSearch] != NSOrderedAscending){
NSLog(#"SYStem version > 7.0");
}
if(delegate&&[delegate respondsToSelector:#selector(commandEntered:)]){
[delegate commandEntered:inputTextField.text];
}
[self dismissViewControllerAnimated:YES completion:nil]; //commened: ^{}
}
#end
DetectionViewController.h
#import <UIKit/UIKit.h>
#import "EnterCommandViewController.h"
#interface DetectionViewController : UIViewController <EnterCommandDelegate>{
}
- (IBAction)showSettings:(UIBarButtonItem *)sender;
#property (nonatomic, strong) EnterCommandViewController* enterCVC;
#property (nonatomic, strong) IBOutlet UILabel *showReceivedCommand;
#end
DetectionViewController.m
#import <Foundation/Foundation.h>
#import "DetectionViewController.h"
#implementation DetectionViewController
#synthesize showReceivedCommand;
#synthesize enterCVC;
- (IBAction)showSettings:(UIBarButtonItem *)sender {
}
-(void) viewDidLoad{
[super viewDidLoad];
}
#pragma mark - EnterCommandDelegate function(s)
-(void)commandEntered:(NSString *)command{
dispatch_async(dispatch_get_main_queue(), ^{
showReceivedCommand.text = command;
});
}
#pragma mark -sugue
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
enterCVC = (EnterCommandViewController*)segue.destinationViewController;
[enterCVC setDelegate:self];
}
#end
Below is what I got when I set a breakPoint AT DetectionViewController.m --> -(void)commmandEntered:(NSString*)command{} --> showReceivedCommand.text = command;
self DetectionViewController * 0x1465132a0 0x00000001465132a0
command NSString * #"testStringJustEntered" 0x000000017424ada0
showReceivedCommand UILabel * 0x1465149d0 0x00000001465149d0
UIView UIView
UIResponder UIResponder
_layer CALayer * 0x17409ae50 0x000000017409ae50
_gestureInfo id 0x0 0x0000000000000000
_gestureRecognizers NSMutableArray * nil 0x0000000000000000
_subviewCache NSArray * #"0 objects" 0x00000001740033b0
_charge float 0 0
_tag NSInteger 0 0
_viewDelegate UIViewController * nil 0x0000000000000000
_backgroundColorSystemColorName NSString * nil 0x0000000000000000
_countOfMotionEffectsInSubtree NSUInteger 0 0
_viewFlags <anonymous struct>
There is nothing Wrong with UILabel, the problem, I guess, is the format of the "commnad" is not compatible with the text in UILabel.
Try follow code for the delegate function:
-(void)commandEntered:(NSString *)command{
dispatch_async(dispatch_get_main_queue(), ^{
NSString* str1=#"";
NSString* str=[str1 stringByAppendingString:command];
showReceivedCommand.text = str;
});
}

Control values overridden by storyboard setting

I have a VC of custom type LVSBBSettingsViewController for user settings. The VC is presented by a main menu in LVSMainViewController. The main VC sets the values of the controls in the settings VC programatically. However, when the settings view appears, the controls all revert to the values assigned to them in the storyboard.
I am using delegation to close the settings view and to pass data from the settings VC back to the main VC when it closes. But I don't think that's what's causing the problem since the same thing happens even if I remove that.
What's causing this? I have a feeling I'm missing something really simple here...
LVSBBSettingsViewController.h:
#import <UIKit/UIKit.h>
#class LVSBBSettingsViewController;
#pragma mark LVSBBSettingsViewController Delegate
#protocol LVSBBSettingsViewControllerDelegate <NSObject>
- (void)settingsViewControllerDidCancel:(LVSBBSettingsViewController *)controller;
- (void)settingsViewControllerDidSave:(LVSBBSettingsViewController *)controller;
#end
#pragma mark LVSBBSettingsViewController
#interface LVSBBSettingsViewController : UITableViewController
#property (nonatomic, weak) id <LVSBBSettingsViewControllerDelegate> delegate;
#property (weak, nonatomic) IBOutlet UISwitch *showBranchVarLabelsSwitch;
#property (weak, nonatomic) IBOutlet UISwitch *useAnimationSwitch;
#property (weak, nonatomic) IBOutlet UISwitch *showAllNodesSwitch;
#property (weak, nonatomic) IBOutlet UILabel *tempLabel;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
#end
LVSBBSettingsViewController.m:
#import "LVSBBSettingsViewController.h"
#interface LVSBBSettingsViewController ()
#end
#implementation LVSBBSettingsViewController
// ... Xcode-generated stuff ...
- (IBAction)cancel:(id)sender
{
[self.delegate settingsViewControllerDidCancel:self];
}
- (IBAction)done:(id)sender
{
[self.delegate settingsViewControllerDidSave:self];
}
#end
LVSBBMainViewController.h:
#import <UIKit/UIKit.h>
#import "LVSBBSettingsViewController.h"
#interface LVSMainViewController : UIViewController <LVSBBSettingsViewControllerDelegate>
#end
LVSBBMainViewController.m:
#import "LVSMainViewController.h"
#import "LVSBBMasterViewController.h"
#interface LVSMainViewController ()
#end
#implementation LVSMainViewController
{
LVSBBMasterViewController *bbmvc;
}
// ...
- (void)viewDidLoad
{
[super viewDidLoad];
// Get main storyboard
UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:#"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
// Instantiate bbmvc
bbmvc = [st instantiateViewControllerWithIdentifier:#"BBMasterViewControllerStoryboard"];
// Initialize settings
bbmvc.showBranchVarLabels = YES;
bbmvc.useAnimation = YES;
bbmvc.showAllNodes = NO;
}
...
#pragma mark LVSBBSettingsViewController Delegate
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"ShowSettings"])
{
// Get pointer to settings VC
UINavigationController *navigationController = segue.destinationViewController;
LVSBBSettingsViewController *settingsViewController = [navigationController viewControllers][0];
// Set delegate
settingsViewController.delegate = self;
// Populate settings VC
// (same problem occurs if I replace right-hand sides of next 3 lines with NO;)
settingsViewController.showBranchVarLabelsSwitch.on = bbmvc.showBranchVarLabels;
settingsViewController.useAnimationSwitch.on = bbmvc.useAnimation;
settingsViewController.showAllNodesSwitch.on = bbmvc.showAllNodes;
settingsViewController.tempLabel.text = #"HELLO";
}
}
- (void)settingsViewControllerDidCancel:(LVSBBSettingsViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)settingsViewControllerDidSave:(LVSBBSettingsViewController *)controller
{
// Set settings in bbmvc
bbmvc.showBranchVarLabels = controller.showBranchVarLabelsSwitch.on;
bbmvc.useAnimation = controller.useAnimationSwitch.on;
bbmvc.showAllNodes = controller.showAllNodesSwitch.on;
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
UPDATE: As a workaround, I added properties in LVSBBSettingsViewController that match the properties in LVSMainViewController. In prepareForSegue:sender:, I set those properties instead of setting the controls directly. Then in viewDidLoad in LVSBBSettingsViewController, I set the control values based on the properties. This seems to work. Still not sure why I can't set the control values directly, though.

Calling a function from a button

Can anyone help me to understand what is going wrong with my function below pls?
I'm fairly new to native IOS dev.
I wanted to implement a side panel into our app using this tutorial (http://www.appcoda.com/ios-programming-sidebar-navigation-menu/).
All that works fine and is straightforward enough - but I wanted to trigger the reveal functionality via a standard button rather than a dynamic button in the header - to suit our design..
The original code is as follows -
#import "SWRevealViewController.h"
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = #selector(revealToggle:);
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
to replicate that functionality triggered by a button I added the following to the .h file -
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (weak, nonatomic) IBOutlet UIButton *revealLeftBtn;
- (IBAction)btnClickRevealL:(id)sender;
and the following in my .m file
- (IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
I get the error 'suspected identifier' for the above lines - I dont understand how the functions triggered with the previous method and not with the above - can anyone help?
Cheers
for reference this is the entire .M file -
#import "MainViewController.h"
#import "SWRevealViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"";
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
[self.navigationController.navigationBar setTranslucent:TRUE];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
#end
This line:
(IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
Does nothing.
I guess this is what you want to do:
[self.revealViewController revealToggle:sender];
When you set the target and the action of a button, you set which class is doing the action (target) and what method is called (action).
that's the equivalent of doing [target action]
- (IBAction)logInBtnClicked:(id)sender {
//Remove WhiteSpace from start of uitextfield
self.emailIdTxtFldRef.text = [self.emailIdTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
self.passwordTxtFldRef.text = [self.passwordTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
if ([self.emailIdTxtFldRef.text isEqualToString:#""]||[self.passwordTxtFldRef.text isEqualToString:#""]) {
[self showMessage:#"All fields are mandatory" withTitle:#"Error"];
}else{
SWRevealViewController *revealVC = [self.storyboard instantiateViewControllerWithIdentifier:#"swRevealViewContoller"];
revealVC.delegate=self;
[[UIApplication sharedApplication]keyWindow].rootViewController = revealVC;
}
}

Sharing data between an IOS Utility Application views

I have created a very basic application using the Utility Application template in Xcode 4.2 in which I want an integer variable obtained from a slider or text field in my FlipsideViewController available in my MainViewController.
I have been searching for hour on global variables but can't find a nice simple answer that works for my specific case.
Please help
(note: I am very new at developing for IOS and objective C. Dumb your answer down for me as much as you are capable!)
Thanks a lot
The following is a basic version of my code showing what I want to do.
FlipSideViewController.h
#import <UIKit/UIKit.h>
#class FlipsideViewController;
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
#interface FlipsideViewController : UIViewController
#property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
- (IBAction)sliderChange:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *sliderValueOnFlipside;
#end
FlipSideViewController.m
#import "FlipsideViewController.h"
#interface FlipsideViewController ()
#end
#implementation FlipsideViewController
#synthesize sliderValueOnFlipside;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setSliderValueOnFlipside:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - Actions
- (IBAction)done:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];
}
- (IBAction)sliderChange:(id)sender {
UISlider *slider = (UISlider *) sender;
int var = [slider value];
sliderValueOnFlipside.text = [NSString stringWithFormat:#"Slider Value is %d",var];
}
#end
MainViewController.h
#import "FlipsideViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
- (IBAction)showInfo:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *sliderValueOnMain;
#end
MainViewController.m
#import "MainViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize sliderValueOnMain;
- (void)viewDidLoad
{
[super viewDidLoad];
sliderValueOnMain.text = [NSString stringWithFormat:#"Slider Value from flipside is %d", var];
}
- (void)viewDidUnload
{
[self setSliderValueOnMain:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
#end
I can easily get the value of the slider to be displayed on the flipside view however I also want that value displayed on the main view.
Global variables are generally frowned upon in polite programming circles.
If you want a method in MainViewController to react to a change in state in FlipsideViewController, then you could make MVC a delegate of FVC, and have FVC call a method on MVC when the value changes.
There's a good explanation of the delegate design pattern here: http://mobiledevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html

Resources