Continuously checking two NSSecureTextField - xcode

how can i make this to keep checking all the time the 2 NSSecureTextFields to know if they are equal/different to display the images without the need of a button?
the .h file:
IBOutlet NSSecureTextField *textField;
IBOutlet NSSecureTextField *textField2;
IBOutlet NSImageView *imagem;
}
- (IBAction)verificarPass:(id)sender;
the .m file:
- (IBAction)verificarPass:(id)sender;
{
NSString *senha1 = [textField stringValue];
NSString *senha2 = [textField2 stringValue];
NSImage *certo;
NSImage *errado;
certo = [NSImage imageNamed:#"Status_Accepted.png"];
errado = [NSImage imageNamed:#"Error.png"];
if ([senha1 isEqualToString:senha2]) {
[imagem setImage:certo];
}else{
[imagem setImage:errado];
}
}

Add a target method to the textField controls, triggered by the UIControlEventEditingChanged control event:
[textField addTarget:self action:#selector(verificarPass:) forControlEvents:UIControlEventEditingChanged];

Related

How to pass value to another controller view in Xcode

How do i get the value from different UIViewController in xcode storyBoard?
I end up using prepareForSegue method.
first i create a string in my third view controller.
#property (strong,nonatomic) NSString* stringFromSecondView;
Then I gave the push segue an ID called "getDate" and in my second view class use this code below and remember to import the thirdviewcontroller.h
#import "thirdViewController.h"
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"getDate"]){
NSString *intro = _myDate.text;
thirdViewController *vc = [segue destinationViewController];
vc.stringFromSecondView = intro;
}
}
Now back to my thirdViewController.m
_myLabel.text = stringFromSecondView;
In your second VIew Controller
- (IBAction) btnPressToBringThirdView : (id) sender
{
ThirdViewController* newObject = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
newObject.labelString = #"whatever text you want";
[self.navigationController pushViewController:newObject];
[newObject release];
}
In your third viewcontroller in .h file
#property (nonatomic, retain) NSString* labelString;
in .m file
- (void)viewDidLoad
{
[super viewDidLoad];
yourLabel.text = labelString;
}
ViewController *secondview=[[ViewController alloc]init];
secondview.your var here= secondview.your var here+100;//whate you var to change if NSintager
///to save your var
[[NSUserDefaults standardUserDefaults]setInteger:secondview.your var here forKey:#"your key to save"];

xCode: Activating an IBAction from within a dynamically added subview

I have a separate UIView class that constructs a simple footer bar that contains a UIButton.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(0, 410, 320, 50)];
if (self) {
int buttonHeight = self.frame.size.height;
int buttonWidth = 70;
int nextBtnPosX =0;
int nextBtnPosY =0;
self.backgroundColor =[UIColor colorWithRed:254.0/255.0 green:193.0/255.0 blue:32.0/255.0 alpha:1.0];
[self sendSubviewToBack:self];
UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[nextBtn setTitle:#"Next" forState:UIControlStateNormal];
nextBtn.frame = CGRectMake(nextBtnPosX, nextBtnPosY, buttonWidth, buttonHeight);
[nextBtn addTarget:self.superview action:#selector(GoToNextPage) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:nextBtn];
}
return self;
}
I have several ViewControllers that then add this footer view class above to each view as a subview.
UIView *newFooter = [[theFooter alloc] init];
[self.view addSubview:newFooter];
Now the actual UIButton within the footer view needs to have its taget different for each viewController it is added to.
So I though it would be best to add the IBAction to the actual view controller then call this via the footer view.
But this is where I have come into a problem. How do I call the parent Controller to init the IBAction(GoToNextPage) from within the footer subview, from the addTarget?
Also would it be easier to have it all within the footer subview and pass in the target required, if so how else would this be done.
Here is a rough overview on what you should do.
This is how your UIView's header file should look
#protocol myViewControllerDelegate <NSObject>
#optional
- (void)didPushButton:(id)sender;
#end
#interface UIViewController : UITableViewController
{
__unsafe_unretained id <myViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <myViewControllerDelegate> delegate;
#end
Remember to #synthesize delegate; in your main file.
Finally in your main file, you will have an IBAction that receives the UIButton action.
Let's say that action is named buttonPushed.
Set that action to:
- (IBAction)buttonPushed:(id)sender
{
if (delegate)
[delegate didPushButton:sender];
}
Finally remember, that you need to set the delegate to each viewController you are using this viewController.
UIView *newFooter = [[theFooter alloc] init];
[self.view addSubview:newFooter];
newFooter.delegate = self;

Xcode: iPad keyboard troubles (not that simple)

I am making an app which uses many Textfields. Most of them are inside static tableViews. I use the split view application template. Every category selected from the left panel presents a storyboard scene inside a second view on the right panel.
I just want to get rid of the keyboard with the "done" button however everything i have tried that would work on a simple view fails to work under these circumstances.
Can you please help me out with this?
p.s. I try to dismiss the keyboard inside the implementation file of the presented storyboard scene. Should i do something inside the Detail Scene of the split view controller?
Here is my Scene's code:
.h
#import <UIKit/UIKit.h>
#interface AfoEsoda : UITableViewController <UITextFieldDelegate>{
}
#property (strong, nonatomic) IBOutlet UITextField *merismataTF;
-(IBAction)hideKeyboard:(id)sender;
#end
.m
#synthesize merismataTF;
- (void)viewDidLoad
{
[super viewDidLoad];
merismataTF.delegate=self ;
}
//---------Hide Keyboard-------------------
//Tried but didn't work
-(IBAction)hideKeyboard:(id)sender {
[merismataTF resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
//Of course i do not use both methods at the same time.
EDIT:
When i set the textfield's delegate to self i get this crash:
Try implementing the textField's delegate, set the delegate to self, and in the delegate's method
- (BOOL)textFieldShouldReturn:(UITextField *)textField
set
[textField resignFirstResponder];
Another way could be going through all of the view's subviews and if it is a text field, resign first responder:
for(int i=0;i<self.view.subviews.count;i++)
{
if([[self.view.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
{
if([[self.view.subviews objectAtIndex:i] isFirstResponder])
[[self.view.subviews objectAtIndex:i] resignFirstResponder];
}}
OK, I got it. Use this with with the textFieldShouldReturn method.
So here is your answer: You have declared your text field as a property and then use alloc and init it over and over again for each cell. Probably it only works properly for the last row.
Here is an example of how your cellForRow method should look like:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *cellIdentifier = #"My cell identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITextField *newTextField;
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
newTextField = [[UITextField alloc] initWithFrame:CGRectMake:(0,0,25,25)];
newTextField.tag = 1;
newTextField.delegate = self;
[cell.contentView addSubview:newTextField];
}
else
newTextField = (UITextField *)[cell.contentView viewWithTag:1];
And then, if you need the textField's value for a certaing row, simply use:
UITextField *someTextField = (UITextField *)[[tableView cellForRowAtIndexPath:indexPath].contentView viewWithTag:1];
NSLog(#"textField.text = %#", someTextField.text);

Core Image help: Setting CIImage from UIImage via UIImagePicker (then filtering it)

Searched around on SO for an answer. Found some interesting stuff but I am still stuck.
In a view controller I have a UIImageView which I set an image taken from UIImagePicker when the view loads.
(I also set a CIImage at the same time)
I have two sliders (one for brightness, one for contrast). Upon moving the slider, a filter is applied to the CIImage, then the CIImage is rendered into the the UIImageView's UIImage.
Fist off, the UIImage taken from UIImagePicker does show up correctly when first selected.
I also have my slider ranges set correctly and have verified the proper float values are being passed to the delegate functions (via NSLog).
However, when I try playing with the sliders, my UIImageView turns white! Perhaps you folks can help. I'll post some code snippets:
First, my #interface:
#interface PrepViewController : UIViewController <UIImagePickerControllerDelegate , UINavigationControllerDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *editingImage;
#property (weak, nonatomic) CIImage *editingCIImage;
#property (weak, nonatomic) CIContext *editingCIContext;
#property (weak, nonatomic) CIFilter *editingCIFilter;
#property (nonatomic) BOOL didAskForImage;
#property (weak, nonatomic) IBOutlet UISlider *brightnessSlider;
#property (weak, nonatomic) IBOutlet UISlider *contrastSlider;
- (void) doImageFilter:(NSString *)filter withValue:(float)value;
#end
My viewDidLoad, pretty simple just sets didAskForImage to NO
- (void)viewDidLoad
{
[super viewDidLoad];
self.didAskForImage = NO;
}
viewDidAppear is where I check if I've already asked for the image, then ask for it
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if(!self.didAskForImage){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
sourceType = UIImagePickerControllerSourceTypeCamera;
}
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
}
}
Here is the imagePickerController didFinishPickingImage delegate method
this is where I actually set the UIImageView's image property and initialize the CIImage, CIContext, and CIFilter objects.
I also set the didAskForImage boolean and the slider targets.
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.didAskForImage = YES;
self.editingImage.image = image;
self.editingCIImage = [[CIImage alloc] initWithImage:image];
self.editingCIContext = [CIContext contextWithOptions:nil];
self.editingCIContext = [CIContext contextWithOptions:nil];
self.editingCIFilter = [CIFilter filterWithName:#"CIColorControls" keysAndValues:kCIInputImageKey, self.editingCIImage, nil];
[self.contrastSlider addTarget:self action:#selector(contrastMove:) forControlEvents:UIControlEventValueChanged];
[self.brightnessSlider addTarget:self action:#selector(brightnessMove:) forControlEvents:UIControlEventValueChanged];
[picker dismissModalViewControllerAnimated:YES];
}
and the cancel delegate
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
picker = nil;
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
Here are the sliders' delegate methods. Again, the NSLogs display the expected values.
- (void) contrastMove:(id)sender{
NSLog(#"%f", [(UISlider *)sender value]);
[self doImageFilter:#"inputContrast" withValue:[(UISlider *)sender value]];
}
- (void) brightnessMove:(id)sender{
NSLog(#"%f", [(UISlider *)sender value]);
[self doImageFilter:#"inputBrightness" withValue:[(UISlider *)sender value]];
}
And finally, here is the doImageFilter method I created, which actually does the filter and reassigns the UIImageView (this is where it turns white)
- (void) doImageFilter:(NSString *)filter withValue:(float)value{
[self.editingCIFilter setValue:[NSNumber numberWithFloat:value] forKey:filter];
CIImage *output = [self.editingCIFilter outputImage];
CGImageRef cgi = [self.editingCIContext createCGImage:output fromRect:[output extent]];
self.editingCIImage = output;
self.editingImage.image = [UIImage imageWithCGImage:cgi];
}
So I have a hunch that the CIImage isn't even being initialized properly in the first place; but I don't know why. Been at this for a couple hours now.
Thanks for all your help!
Cheers
Hahaha, oh wow.
So I figured it out, my CIContext and CIFilter need to be set to strong instead of weak.
Awesome.

How do I put a background image on a text area (IN THE IPAD)

How do I put a template'd background image on a text area?
Not sure what you mean with "template'd"... but....
In interface builder, add the imageview behind the textview, uncheck the "opaque" box for the textview.
You can set the contents property of the text views layer.
#import <QuartzCore/QuartzCore.h>
...
- (void) viewDidLoad {
[super viewDidLoad];
textView.layer.contents = (id)[UIImage imageNamed:#"myImage.png"].CGImage
}
should work
If you want to add the image programmaticaly I managed to do it this way:
First in my textviewViewController.h I added an outlet for the UITextView.
#import <UIKit/UIKit.h>
#interface textviewViewController : UIViewController {
UITextView *textView;
}
#property (nonatomic, retain) IBOutlet UITextView *textView;
#end
Next, in my .xib I added my UITextView and connected my outlet.
Lastly in the viewDidLoad of textviewViewController.m I add the image as a subview to my textview.
- (void)viewDidLoad {
[super viewDidLoad];
// Change the pathForResource to reflect the name and type of your image file
NSString *path = [[NSBundle mainBundle] pathForResource:#"d" ofType:#"jpg"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.textView insertSubview:imgView atIndex:0];
[imgView release];
}
I tried the insertSubview:atIndex: with both 0 and 1 with the same result, but I would stick with 0 idicating that it's behind the textview.

Resources