setAutoresizingMask from code in osx

Loading...

setAutoresizingMask from code in osx

There is a section in size inspector with name Atosizing that can set left,right,up,down layout of a control,i find that i do that with setAutoresizingMask but don't know how set it that my control layout to right and up (means when user resize window my control steak to right and up)

Solutions/Answers:

Answer 1:

Look at these -setAutoresizingMask parameters:

NSViewNotSizable

References

Loading...

Using Same UIDatePicker For Two TextFields

Loading...

Using Same UIDatePicker For Two TextFields

i am having two textfields,fromdate and todate.how to get different dates from the same datepicker.i tried something which ended up in getting the same date in both the textfields when the date is changed.
-(IBAction)dateValueChanged:(id)sender
{
        UIDatePicker *picker = (UIDatePicker *)sender;
        NSDate *dateSelected1 = [picker date];
        NSDate *dateSelected2 = [picker date];

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"dd-MM-yyyy"];
        self.fromTextField.text = [dateFormatter stringFromDate:dateSelected1];
       self.toTextField.text = [dateFormatter stringFromDate:dateSelected2];
}

Solutions/Answers:

Answer 1:

You could implement the UITextFieldDelegate Protocol for both your TextFields textFieldDidBeginEditing: Method along with setting the tag property for each TextField so they are easily identifiable…

Then when textFieldDidBeginEditing: is called, you could read the tag of the textfield that has begun editing and set that as a global value so you can find out what textfield the date picker should change.. example:

- (void)textFieldDidBeginEditing:(UITextField *)textField {

     someGlobalNSInteger = textField.tag; //the current text field tag is now globally set

}

-(IBAction)dateValueChanged:(id)sender {
    UIDatePicker *picker = (UIDatePicker *)sender;
    NSDate *dateSelected1 = [picker date];
    //NSDate *dateSelected1 = [picker date];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];

    //self.fromTextField.text = [dateFormatter stringFromDate:dateSelected1];
    //self.toTextField.text = [dateFormatter stringFromDate:dateSelected2];

    UITextField *activeTextField = (UITextField*)[self viewWithTag:someGlobalNSInteger]; //gets text field what is currently being edited
    [activeTextField setText:[dateFormatter stringFromDate:dateSelected1]];

}

However if you’re not allowing the text field to be editable (so it can’t bring the keyboard up) you may need some other way of figuring out what textField should get the updated date but i’ll leave that to you.

Hope it helps

Answer 2:

A more elegant way available of implementing this without UITextFieldDelegate and textFieldDidBeginEditing:

Just with checking firstResponder

- (IBAction)dateValueChanged:(id)sender
{
    NSDate *dateSelected = [picker date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];

    if ([firstTextField isFirstResponder])
    {
      firstTextField.text = [dateFormatter stringFromDate:dateSelected];
    }
    else if ([self.endTextField isFirstResponder])
    {
        secondTextField.text = [dateFormatter stringFromDate:dateSelected];
    }
}

Answer 3:

The best way to achieve this is to use inputview property available in the UITextField. Initialize your date picker once either using Outlet or programming & assign it as inputView in the textfield’s delegate method “textFieldDidBeginEditing:”. For assigning date you may use your own business logic before actually assigning the inputview to the textfield.

References

Loading...