Short solution for short problems

iOS: Performing a segue using a splash screen.

My application was using a dash board, from where the user navigates through the application. Works file until some large forms take more then a second or so to load. Then it might appear that the form is doing nothing. So a simple solution is to show a waiting screen while performing the segue. The only little trick is that you call the perform segue with a delay and before you do that show your waiting screen. Else the thread will wait to output to GUI until the segue is done and you will not see the splash screen.

So here just a little piece of code:

-(void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath




        NSString * label = [store.HomeButtonsArray objectAtIndex:indexPath.item];

        //Show the waiting popup (Change it here to match your waiting popup)

        hud = [GeneralFunctionsGetMBProgressHUDForView:self.view];

        hud.detailsLabelText = [[storeTranslate: @"$MOB$Loading"] stringByAppendingString:[@" : "stringByAppendingString:label]];



        [self performSelector:@selector(segueWithLabel:) withObject:label afterDelay:0.2];

        //[self performSegueWithIdentifier:[NSString stringWithFormat:@"DashB%@",label] sender:nil];


    @catch (NSException *exception) {



    @finally {





-(void) segueWithLabel:(id) label


    [selfperformSegueWithIdentifier:[NSStringstringWithFormat:@"DashB%@",label] sender:nil];


if a collection view item is pressed, the segue starts after 0.2 seconds, but first a waiting popup will be send to the screen.
Then when the view disappears, I hide the waiting popup:

-(void) viewDidDisappear:(BOOL)animated




iOS: UITextView Maximum length in TableView or Collection View

I was using a UITextView with a custom layout that shows the borders like a textfield. I also needed a fixed length, to use in a collection view. Off course they didn't provide this simple feature. So I implemented it myself. For starters I added an extra property to my custom TextView: MaxLength. By default its 0 and when its 0, the text will be unlimited. If I set it to more then 0 the text will be limited to this number.

#import <UIKit/UIKit.h>


@interface MyTextView : UITextView


@property int MaxLength;



In the initializer I set this property to 0, also I add the borders so it looks like a normal textfield:

- (id)initWithCoder:(NSCoder *)aDecoder


    self = [super initWithCoder:aDecoder];

    if (self) {

        // Initialization code






(Here's the MakeTextField function for those who are interested:)

+(void) MakeTextField:(UITextView *) vw


    vw.backgroundColor = [UIColorclearColor];

    UIImageView *borderView = [[UIImageViewalloc] initWithFrame: CGRectMake(0, 0, vw.frame.size.width, vw.frame.size.height)];

    borderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    UIImage *textFieldImage = [[UIImageimageNamed:@"TextField.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 8, 15, 8)];

    borderView.image = textFieldImage;

    [vw addSubview: borderView];

    [vw sendSubviewToBack: borderView];


Now I implement the UITextViewDelegate on the control where it's used (I've set the MaxLength property using the runtime attributes in the attribute inspector of the story board):

-(BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text


    if ([textView isKindOfClass:[MyTextView class]] && ((MyTextView *)textView).MaxLength>0 )


        NSUInteger newLength = [textView.text length] + [text length] - range.length;

        return (newLength > ((MyTextView *)textView).MaxLength) ? NO : YES;




        return YES;