Dailycode.info

Short solution for short problems

iOS : Custom Flip Segue (portrait and landscape layout) xcode 4

Using segues is really easy. Get use to the visual programming! If you draw segues its still a shame that you cannot visual change the animation on the segues. But then the implementation of a custom animation is not so hard.

First create a new Objective C class and give it a usefull name. For example: FlipSegue. 

This class should inherit from the UIStoryboardSegue.

#import <UIKit/UIKit.h>

 

@interface FlipSegue : UIStoryboardSegue

 

@end

Then in the implementation file we override the perform method. Below you can see that I do a check if the orientation is landscape or portrait, because then you will always flip from left to right. If not, when you change orientation, it will flip from top to bottom. Here is the full code for the custom segue implementation.

#import "FlipSegue.h"

 

@implementation FlipSegue

- (void)perform

{

    UIInterfaceOrientation orientation = [self.sourceViewControllerinterfaceOrientation];

    if (UIInterfaceOrientationIsPortrait(orientation))

    {

        UIViewController *src = (UIViewController *) self.sourceViewController;

        UIViewController *dst = (UIViewController *) self.destinationViewController;

        [UIViewtransitionWithView:src.navigationController.view duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft

                    animations:^{

                        [src.navigationController pushViewController:dst animated:NO];

                    }

                    completion:NULL];

    }

    else

    {

        UIViewController *src = (UIViewController *) self.sourceViewController;

        UIViewController *dst = (UIViewController *) self.destinationViewController;

        [UIViewtransitionWithView:src.navigationController.view duration:0.8 options:UIViewAnimationOptionTransitionFlipFromBottom

                        animations:^{

                            [src.navigationController pushViewController:dst animated:NO];

                        }

                        completion:NULL];

    }

}

 

@end

Now the last thing we need to do is tell the Segue that it has to inherit from this class:


iOS: Change Navigation Item text inside a Tab Bar Controller

I have an application that uses a navigation controller. After a login screen it navigates to a tab bar controller. The problem was the when tab bars where pressed, the navigation item text was not changed. It show the navigation item text that was set on the tab bar controller.

 

So the way to solve this was to implement a custom UITabBarController. Assign this to your TabBarController as class. Then in the implementation of the custom tab bar controller, you can change the navigation item text according to the tab bar item that was chosen:

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

    self.navigationItem.title = [self.tabBar.items[0] title];

}

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void) tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

{

    self.navigationItem.title = item.title;

}


Drop tables procedure for .Net and MS SQL

I wrote a simple procedure that will drop tables in a database that have a certain prefix. 

First I initiate the process layer:

MESCockpitProcessLayer.DirectDataAccess pl = new MESCockpitProcessLayer.DirectDataAccess();

Then I will fill a dataset with the following statement:

//This script will get all tables with the selected prefix and generates a drop statement. I load it in a dataset, each drop statement

//is a row

string DropTableString = "SELECT 'DROP TABLE ' + TABLE_NAME + ' ' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'GP_MES%'";

DataSet ds = pl.GetDataSet(new StringBuilder(DropTableString), serverName, DBName, DBUserName, DBUserPWD);

Next I simply go over each row in the dataset table and execute the statement:

if (ds != null)

{

    foreach (DataRow table in ds.Tables[0].Rows)

    {

        //Drop the table using the generated script

        pl.ExecuteQueryDirect(new StringBuilder(table[0].ToString()), serverName, DBName, DBUserName, DBUserPWD);

    }

}


The generated statement look like this:

DROP TABLE EventLog 

The data class that gets the data and executes the SQL statements is just the very simplest using the Data.SqlClient:

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace MESCockpitDataLayer.SqlClient

{

    publicclassMESDataAccess

    {

        publicstaticint ExecuteNonQuery(StringBuilder sb, string connectionString)

        {

            SqlConnection conn = null;

            SqlCommand executeCommand = null;

            //SqlTransaction MyTrans = null;

            try

            {

                conn = newSqlConnection(connectionString);

                conn.Open();

 

                executeCommand = newSqlCommand(sb.ToString(), conn);

                return executeCommand.ExecuteNonQuery();

            }

            catch (Exception er)

            {

                //Handle exception.

                throw er;

            }

        }

 

        publicstaticobject ExecuteScalar(StringBuilder sb, string connectionString)

        {

            SqlConnection conn = null;

            SqlCommand executeCommand = null;

            //SqlTransaction MyTrans = null;

            try

            {

                conn = newSqlConnection(connectionString);

                conn.Open();

 

                executeCommand = newSqlCommand(sb.ToString(), conn);

                return executeCommand.ExecuteScalar();

            }

            catch (Exception er)

            {

                //Handle exception.

                throw er;

            }

        }

 

        publicstaticDataSet GetDataSet(StringBuilder sb, string connectionString)

        {

            SqlConnection conn = null;

            SqlCommand executeCommand = null;

            SqlDataAdapter MyDataAdapter = null;

            DataSet returnDS = newDataSet();

            try

            {

                MyDataAdapter = newSqlDataAdapter();

               

                conn = newSqlConnection(connectionString);

                conn.Open();

 

                executeCommand = newSqlCommand(sb.ToString(), conn);

                MyDataAdapter.SelectCommand = executeCommand;

               

                MyDataAdapter.Fill(returnDS);

                return returnDS;

            }

            catch (Exception er)

            {

                //Handle exception.

                throw er;

            }

        }

    }

}

 


0171701 calling me at strange hours

This number was calling me at random time during the day. I found a lot of explanations, but none were close to the truth. I called the provider Belgacom today and they said that someone tried to sms or mms my home phone. But our device doesn't have this option, so it was not able to respond to this. Now they blocked this number.