depicus

changing the digital world one bit at a time...

Blants (noun) the rants of a blogger

  1. Depicus on the iPhone ?

    October 10, 2010 by The Man

    Hell yes……soon.


  2. iDev – hiding the keyboard for a UITextView

    August 5, 2010 by The Man

    Lots of into for a UITextField but not a UITextView.

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        if ([text isEqualToString:@"n"])
        {
            [textView resignFirstResponder];
            return NO;
        }
        return YES;
    }
    

  3. iDev – Getting a good looking date with prefix

    by The Man

    Not sure it should take this much code but….

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"MMMM yyyy"];
        
        NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
        [timeFormat setDateFormat:@"HH:mm"];
        
        NSDateFormatter *dayFormat = [[NSDateFormatter alloc] init];
        [dayFormat setDateFormat:@"d"];
        
        NSDate *now = [[NSDate alloc] init];
        
        NSString *theDate = [dateFormat stringFromDate:now];
        NSString *theTime = [timeFormat stringFromDate:now];
        NSString *theDay = [dayFormat stringFromDate:now];
        
        NSString *dayWithPrefix;
        
        if ((theDay == @"1") || (theDay == @"21") || (theDay == @"31"))
        {
            dayWithPrefix = [NSString stringWithFormat:@"%@st", theDay];
        }
        else if ((theDay == @"2") || (theDay == @"22"))
        {
            dayWithPrefix = [NSString stringWithFormat:@"%@nd", theDay];
        }
        else if ((theDay == @"3") || (theDay == @"23"))
        {
            dayWithPrefix = [NSString stringWithFormat:@"%@rd", theDay];
        }
        else
        {
            dayWithPrefix = [NSString stringWithFormat:@"%@th", theDay];
        }
        
        
        [lblDateTime setText:[NSString stringWithFormat:@"Date: %@ %@ Time: %@", dayWithPrefix, theDate, theTime]];
    
        [dateFormat release];
        [timeFormat release];
        [theDay release];
        [now release];
    
    

  4. Loop through controls on a UIView

    August 2, 2010 by The Man

    Easier than I thought. My view is called vTools and the controls I want to hide are all tagged 101.

    for (id subview in vTools.subviews) {
            if ([subview tag] == 101) {
                [subview setHidden:YES];
            }
        }
    

  5. Get rid of the iPhone keyboard when “Done”

    August 1, 2010 by The Man

    Another one I always forget. Get rid of the keyboard when the done button is pressed.

    1. In IB make sure the delegate of the UITextField is set to the File’s Owner.

    2. Add this code

    -(BOOL) textFieldShouldReturn:(UITextField*) textField {
        [textField resignFirstResponder]; 
        return YES;
    }
    

    Easy really.


  6. Show me the next iView

    July 31, 2010 by The Man

    Because I always forget ….

    1. In the starting .h file

    #import "frmMain.h"
    @interface frmStart : UIViewController 
    

    2. In the starting form .m file

    #import "frmMain.h"
    
    @synthesize delegate;
    
    -(void) onPressMain {
      NSString *nibVersion = @"frmMain";
    if (iPadCheck)
    {
        NSLog(@"Is an iPad");
        nibVersion = @"frmMainiPad";
    }
    frmMain *controller = [[frmMain alloc] initWithNibName:nibVersion bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];  
    }

    2. In the starting .h file

    #import "frmMain.h"
    
    -(void) onPressMain {
      NSString *nibVersion = @"frmMain";
    if (iPadCheck)
    {
        NSLog(@"Is an iPad");
        nibVersion = @"frmMainiPad";
    }
    frmMain *controller = [[frmMain alloc] initWithNibName:nibVersion bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];  
    }
    
    - (void)frmMainDelegateDidFinish:(frmMain *)controller {
    	[self dismissModalViewControllerAnimated:YES];
    }
    

    3. In the main .h file

    @protocol frmMainDelegate;
    
    @interface frmMain : UIViewController {
        id  delegate;
        UIWindow *window;
        UITabBarController *tabBarController;
    }
    
    @property (nonatomic, assign) id  delegate;
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    
    @end
    
    @protocol frmMainDelegate
    
    - (void)frmMainDelegateDidFinish:(frmMain *)controller;
    
    @end
    

    4. In the main .m file

    @synthesize delegate;