Top 10 reads of February 2015

These are the Top 10 reads of February 2015.


  • How to show or hide a variable if null in AngularJS
  • How to remove an element using Javascript
  • How to replace the inner HTML of a div using jQuery
  • How to reload or rerender the page using AngularJS
  • How to check if an array contains a value in Javascript
  • How to define global Variables in AngularJs
  • How to set the HTTP Header for a request using AngularJs
  • How to resize a image proportionally with CSS
  • How to join two lists in C# and VB.NET
  • How to clear notifications in IOS using Objective-C



  • thanks to all visitors, bookmark us, share us, talk about us, Follow us!, Like us! let’s grow bigger!




    How to reload a ViewController in IOS using Objective-C

    To reload a UITableViewController in IOS using Objective-C you can simply use the reloadData method of the ViewController.

    //MyTablViewController is a UITableViewController
    [MyTableViewController.tableView reloadData] 
    




    How to trim a string using XSL 1.0

    Since XSL 1.0 dows not have inbuild Trimming functions for Strings, you need to define your own templates.
    You can use the Trim Templates shown in the codesnippet below.

    Sample XSL

    <xsl:variable name="whitespaceCharacters" select="'&#09;&#10;&#13; '" />
        
        <!-- Trim Right side of the String -->
        <xsl:template name="TrimRight">
            <xsl:param name="input" />
            <xsl:param name="trim" select="$whitespaceCharacters" />
            
            <xsl:variable name="length" select="string-length($input)" />
            <xsl:if test="string-length($input) &gt; 0">
                <xsl:choose>
                    <xsl:when test="contains($trim, substring($input, $length, 1))">
                        <xsl:call-template name="TrimRight">
                            <xsl:with-param name="input" select="substring($input, 1, $length - 1)" />
                            <xsl:with-param name="trim" select="$trim" />
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$input" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:template>
        
        <!-- Trim Left side of the String -->
        <xsl:template name="TrimLeft">
            <xsl:param name="input" />
            <xsl:param name="trim" select="$whitespaceCharacters" />
            
            <xsl:if test="string-length($input) &gt; 0">
                <xsl:choose>
                    <xsl:when test="contains($trim, substring($input, 1, 1))">
                        <xsl:call-template name="TrimLeft">
                            <xsl:with-param name="input" select="substring($input, 2)" />
                            <xsl:with-param name="trim" select="$trim" />
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$input" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:template>
        
        <!-- Trim both sides of the String -->
        <xsl:template name="Trim">
            <xsl:param name="input" />
            <xsl:param name="trim" select="$whitespaceCharacters" />
            <xsl:call-template name="TrimRight">
                <xsl:with-param name="input">
                    <xsl:call-template name="TrimLeft">
                        <xsl:with-param name="input" select="$input" />
                        <xsl:with-param name="trim" select="$trim" />
                    </xsl:call-template>
                </xsl:with-param>
                <xsl:with-param name="trim" select="$trim" />
            </xsl:call-template>
        </xsl:template>
    




    How to hide the status bar while Splashscreen is Shown in IOS

    To hide the status bar while Splashscreen is Shown in IOS follow these Steps.

  • 1. Open the Info.plist File.
  • 2. Search for the “Status bar is initially hidden” property and set it to checked.
  • if you do not have the “Status bar is initially hidden” property, simply add it by selecting the last line in the File and then click the plus button on the right end of the line.

    To show the status bar you can use this snippet.

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; //UIStatusBarAnimationNone, UIStatusBarAnimationFade or UIStatusBarAnimationSlide
    




    How to get return Value from method invocation using reflection in C# and VB.NET

    To get return Value from method invocation using reflection in C# and VB.NET you can use the snippet below.

    Sample C#

    var returnValue = (Int32)methodInfo.Invoke(null,null); //just cast the returned object of Invoke to the needed Type. Theres no difference if it is a static method/class or not
    

    Sample VB.NET

    Dim returnValue = DirectCast(methodInfo.Invoke(Nothing, Nothing), Int32) 'just cast the returned object of Invoke to the needed Type. Theres no difference if it is a static method/class or not
    

    For more informations on how to invoke methods from other assemblies using reflection see:

  • How to call a static method in different assembly using Reflection in C# and VB.NET
  • How to call a non-static method in different assembly using Reflection in C# and VB.NET



  • How to call a non-static method in different assembly using Reflection in C# and VB.NET

    To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

    Sample C#

    Assembly assembly = Assembly.LoadFile(@"Assembly_Location");   
    var type = assembly.Types().FirstOrDefault(x => x.FullName.Contains("MyClassName"));
    var constructor = type.GetConstructor(Type.EmptyTypes);
    
    var classObject = constructor.Invoke(new object[] { }); //call parameterless constructor
    var classObject = constructor.Invoke(new object[] { param1 }); //call non-parameterless constructor
    
    MethodInfo methodInfo = type.GetMethod("MyMethodName");
    methodInfo.Invoke(classObject, new object[] { }); //pass classobject, parameterless method
    methodInfo.Invoke(classObject, new object[] { param1 }); //pass classobject, parameterized method
    

    Sample VB.NET

    Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
    Dim type__2 = assembly__1.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
    Dim constructor = type__2.GetConstructor(Type.EmptyTypes)
    
    Dim classObject = constructor.Invoke(New Object() {})'call parameterless constructor
    Dim classObject = constructor.Invoke(New Object() {param1})'call non-parameterless constructor
    
    Dim methodInfo As MethodInfo = type__2.GetMethod("MyMethodName")
    methodInfo.Invoke(classObject, New Object() {})'pass classobject, parameterless method
    methodInfo.Invoke(classObject, New Object() {param1})'pass classobject, parameterized method
    




    How to call a static method in different assembly using Reflection in C# and VB.NET

    To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

    Sample C#

    Assembly assembly = Assembly.LoadFile(@"Assembly_Location"); 
    var t = assembly.Types().FirstOrDefault(x=>x.FullName.Contains("MyClassName"));
    var method = t.GetMethod("MyMethodName", BindingFlags.Public | BindingFlags.Static);
    method.Invoke(null, null); //assuming that the method does not have parameters
    method.Invoke(null, new object[] { param1}); //assuming that the method has 1 parameter
    

    Sample VB.NET

    Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
    Dim t = assembly.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
    Dim method = t.GetMethod("MyMethodName", BindingFlags.[Public] Or BindingFlags.[Static])
    method.Invoke(Nothing, Nothing) 'assuming that the method does not have parameters
    method.Invoke(Nothing, New Object() {param1}) 'assuming that the method has 1 parameter
    




    How to use substring in IOS using Objective-C

    To use substring in IOS using Objective-C you can use the snippet below.

    Sample Objective-C

    NSString *myString = @"http://codesnippets.fesslersoft.de";
    NSString *myNewString = [myString substringFromIndex:7]; //myNewString will be "codesnippets.fesslersoft.de"
    




    How to autosize UILabel to Textsize in IOS using Objective-C

    labelTest.text = @"This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.";
    labelTest.numberOfLines = 0;
    [labelTest sizeToFit];
    




    How to clear notifications in IOS using Objective-C

    To clear notifications in IOS using objective-c you can use the snippet below.

    Sample Objective-C

    //in method: application:didFinishLaunchingWithOptions
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    
    //in method: application:didReceiveRemoteNotification
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1]; //we need to to increment first
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];