depicus

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

Blants (noun) the rants of a blogger

  1. 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];
            }
        }
    

  2. 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.


  3. 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;