Dailycode.info

Short solution for short problems

iOS: FreeForm and UIScrollview: subviews do not react to scroll

After upgrading to iOS7 I've had some problems with a FreeForm combination with a UIScrollview.

First it didn't scroll at all, this was related to missing constraints. Then I noticed that some subviews were not sending their touches to the scrollview, or that the scrollview didn't react ot touches on subviews. 

After settings the 'Delays Content Touches' to YES, it worked again as normal.

What a relief.


iOS: Open second storyboard in modal with presentation curl.

I had a very large StoryBoard with a lot of relations. I started to group functionality and add the Views to different storyboards. Since iOS 7 and xcode 5 it came in a hurry, since the designer was crashing and messing up the layout.

First I just pushed the viewcontrollers in the navigation controller like this:

+(void) NavigateToCustomerLookupFrom:(UIViewController *)vc

{

    UIStoryboard * sb = [UIStoryboardstoryboardWithName:@"CustomerLookupStoryboard"bundle:nil];

    UIViewController * vcTo = [sb instantiateInitialViewController];

    

    [UIViewtransitionWithView:vc.viewduration:0.8options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:^{

                        [vc.navigationController pushViewController:vcTo animated:NO];

                    }

                    completion:NULL];

    

}

That worked. But then I came up with a views that needed to be opened in a modal way. So this is the code to do just that. In this example I use the partial curl effect to open it:

+(void) NavigateToSignatureFrom:(UIViewController *)vc withSignee:(NSString *) Signee

{

    UIStoryboard * sb = [UIStoryboardstoryboardWithName:@"SignatureStoryboard"bundle:nil];

    UIViewController * vcTo = [sb instantiateInitialViewController];

    

    ((SignatureVC *) vcTo).Signee = Signee;

    

    [vcTo setModalTransitionStyle:UIModalTransitionStylePartialCurl];

    [vc presentViewController:vcTo animated:YEScompletion:nil];

}

The example also shows how to set properties of the destination controller.


xcode5: story board crashes

After upgrading to xcode 5, my xcode crashed when I opened a story board with some 20 Views on it. 

I tried several solutions, including waiting, clicking, wainting. But everytime the xcode seemed like loading and responded for a click every minute or so.

The reason the story board crashed, was apparently because I clicked once on the keep xcode 4.6 compatible. This made xcode crash. It started scanning the files and ...

So how to solve thisjQuery15201013488220050931_1381145930681

Right click on the storyboard and choose: 'Open As' -> Source code.

There you need to change the top of the document to be xcode 5 comatible. You can get the code from a story board in your solution that is working, or you can try to replace the code on the top of the document up until </dependencies> with this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES">

    <dependencies>

        <deployment defaultVersion="1552" identifier="iOS"/>

        <development version="5000" identifier="xcode"/>

        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>

    </dependencies>

 

You can now switch the View As to 'iOS 6.1 and Earlier' or 'iOS 7.0 and Later'.

You'll find this in the identity inspector when clicking on the story board outside of a view.


xcode5: story board crashes

After upgrading to xcode 5, my xcode crashed when I opened a story board with some 20 Views on it. 

I tried several solutions, including waiting, clicking, wainting. But everytime the xcode seemed like loading and responded for a click every minute or so.

The reason the story board crashed, was apparently because I clicked once on the keep xcode 4.6 compatible. This made xcode crash. It started scanning the files and ...

So how to solve thisjQuery15201013488220050931_1381145930680

Right click on the storyboard and choose: 'Open As' -> Source code.

There you need to change the top of the document to be xcode 5 comatible. You can get the code from a story board in your solution that is working, or you can try to replace the code on the top of the document up until </dependencies> with this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES">

    <dependencies>

        <deployment defaultVersion="1552" identifier="iOS"/>

        <development version="5000" identifier="xcode"/>

        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>

    </dependencies>

 


iOS: Hide keyboard on edit begin before picker view

I wanted to show a picker view in a popup when I click in a text field. But I do not want to show the keyboard. Now this was not a problem when you click directly in the textfield. But when coming from another textfield with the keyboard enabled, the keyboard stayed visible. 

I solved it with a simple call before I show the picker view:

- (IBAction)LocationDidBegin:(id)sender

{

    [self.txtLocation performSelector:@selector(resignFirstResponder) withObject:nil afterDelay:0.2];

    [selfShowLocationPicker];

}

So that did the trick.


iOS: cannot find manuel segue

I had an application with a dashboard with dynamic number of button. Based on the button description, a segue would be triggered. This works fine. But at a moment, a certain push segue was not found. So I triple checked the name, debugged and debugged, but could not find the problem. Also the application did no respond to other segues anymore. 

The problem was that I copy a view controller on the story board, then changed it and created a new manuel segue to it. Were the view controller of which I copied the new VC from was also referring. This was causing the problem. I guess there is somewhere still a reference because it was a copy. 

Now I solved it by simply adding a new view controller to the story board, then copy paste all controls to this and changed the view controller class. Deleted the first copy, then set the manual segue to the new view controller and everything worked. I had to hook up all the outlets and events off course. 


Read and write windows forms textboxes into DTO

Without using any kind of existing binding protocols, these functions will fill the controls with the corresponding fields from a class (DTO in this case).

The most important requirement in this case is that you name the textfields like your DTO properties. you can use a random prefix for the text fields. Contain the text fields in a panel or group box. Then for eg. each group box use a different container. In my case I had several tab pages, for each tab page I use a prefix txt1 up to txt5. So a text field is called txt1CREATED or ...

The first function is to Fill the fields on the form. You provide a DTO class, a container and a number that is equal to the number of prefix characters.

    Private Sub FillDataFieldsOnForm(Of T)(ByVal DTO As T, ByVal collection As Control.ControlCollection, ByVal i As Short)

        Dim myType As Type = GetType(T)

 

        For Each txt In collection

            If (TypeOf txt Is DevExpress.XtraEditors.TextEdit) Then

                Try

                    Dim name As String = DirectCast(txt, DevExpress.XtraEditors.TextEdit).Name.Substring(i)

                    Dim myProp As PropertyInfo = myType.GetProperty(name)

 

                    DirectCast(txt, DevExpress.XtraEditors.TextEdit).EditValue = myProp.GetValue(DTO, Nothing)

                Catch ex As Exception

                    DirectCast(txt, DevExpress.XtraEditors.TextEdit).EditValue = ex.Message

                End Try

            End If

        Next txt

 

    End Sub

Here you can see an implementation of this function:

FillDataFieldsOnForm(kKna1, grpHeader.Controls, 3)

Now when you want to read the controls, its equally easy:

ReadDataFieldsOnForm(Of KNB1)(kKnb1, grpCustomerMasterData, 4)

The function for to do this is:

    Private Sub ReadDataFieldsOnForm(Of T)(ByVal DTO As T, ByVal grp As DevExpress.XtraEditors.GroupControl, ByVal i As Short)

        Dim myType As Type = GetType(T)

 

        For Each txt In grp.Controls

            If (TypeOf txt Is DevExpress.XtraEditors.TextEdit) Then

                Try

                    Dim name As String = DirectCast(txt, DevExpress.XtraEditors.TextEdit).Name.Substring(i)

                    Dim myProp As PropertyInfo = myType.GetProperty(name)

 

                    myProp.SetValue(DTO, DirectCast(txt, DevExpress.XtraEditors.TextEdit).EditValue, Nothing)

                Catch ex As Exception

                End Try

            End If

        Next txt

 

    End Sub