Hello World! First iphone App

From today we will begin learning ios. We will begin with hello world application and will keep learning through out. with each learning you can find sample application for downloading.

In the xcode 5 and above, we do not get xib or interface builder, but instead we get storyboard where we do all designing stuffs. Let us start our hello world program now.

1. First of all open xcode. create a new project as shown below:

Screen Shot 2014-11-16 at 7.43.16 PM

2. Within Application , Choose Application , then select single view application:
Screen Shot 2014-11-16 at 7.46.12 PM

3: then enter the product name as helloworld.

Screen Shot 2014-11-16 at 7.47.17 PM

syntax highlighting in wordpress

To accomplish the syntax highlighting, just wrap your code in these tags:

33

Where Your_used_langauge can be

  • actionscript3
  • bash
  • clojure
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • python
  • ruby
  • scala
  • sql
  • vb
  • xml

Embed Youtube video in html

1. open your youtube link
2. Click on Share link, just below the subscribe button
11

3. You can see Embed link after clicking on share.

[There you find iframe code ]

4. copy iframe code and paste in your html file.

22

Iframe code

5. You can customize video width and height manually or can do it clicking on more option with some other options as well.

Iframe video in html displays as:

Insert Data using JSON ASP.NET Web services and jQuery

Hello everyone, today we will learn how to insert data in sql server database using json asp.net web services.
In sql server Database:
– Create your database
– Create a table with fields “Name, PhoneNumber, Email, Address”

2

In Visual Studio 2010
1. Open visual studio.
2. Go to file- new – website
3. Type your project name

1

Let us first create aspx page which will send our input values to the asmx page. Here we are using jquery -ajax for sending datas to .asmx page which will insert those data to sql database.

1. Now create a new aspx page

  • In solution explorer, right click then add new item
  • Select Web form
  • Enter page name eg:InsertData.aspx

3

2. Copy the below code in your aspx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        function CallJsonService() {

            // Creating variables to hold data from textboxes
            var name = $('#_txtname').val();
            var phone = $('#_phone').val();
            var email = $('#_email').val();
          
            var addr = $('#_addr').val();
            alert(name);
            $.ajax({
                type: "POST",
                url: "insertdatajson.asmx/ReceiveWebservice",
                data: "{ 'name': '" + name + "','phone': '" + phone + "', 'email': '" + email + "','address':'" + addr + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (data) {
                    $('#message').text(data.d);
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div><B> DATA INSERTION  USING JSON ASP.NET WEB SERVICES AND JQUERY</B></div><br /><br />
    <div style="margin:0 auto;width:1000px;">
        Name:
        <asp:TextBox ID="_txtname" runat="server"></asp:TextBox><br /><br />
         Phone:
        <asp:TextBox ID="_phone" runat="server"></asp:TextBox><br /><br />
        Email:
        <asp:TextBox ID="_email" runat="server"></asp:TextBox><br /><br />
       
        Adrss:
        <asp:TextBox ID="_addr" runat="server"></asp:TextBox><br /><br />
        <input id="_btnSubmit" type="button" value="Submit" onclick="CallJsonService();" />
        <span id="message"></span>
    </div>
    </form>
</body>
</html>

In the above code we are making post ajax call, where type is POST method, and the page to be called is insertdatajson.asmx and the data refers to the data to be passed to asmx page.On successful insertion we get success message.

3. In your web config file , add the connectionstring as :

 <connectionStrings>
    <add name="con" connectionString="server=ANIL-PC;uid=sa;pwd=emizr123;database=ServerCommunication"/>
  </connectionStrings>

4. Now again in solution explorer, add new item, select web service .
Name it as insertdatajson.asmx

4

5. In insertdatajson.asmx add the following code.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;


/// <summary>
/// Summary description for insertdatajson
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class insertdatajson : System.Web.Services.WebService {

    public insertdatajson () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    // getting connection string
    string conStr = WebConfigurationManager.ConnectionStrings["con"].ConnectionString;
    int rowsInserted = 0;
    [WebMethod]
    public string ReceiveWebservice(string name,string phone ,string email,  string address)
    {
        // Creating Sql Connection
        using (SqlConnection conn = new SqlConnection(conStr))
        {
            // Creating insert statement
            string sql = string.Format(@"INSERT INTO tbl_your_profile ([Name],[PhoneNumber],[Email],[Address])VALUES('{0}','{1}','{2}','{3}')", name,phone, email,  address);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            conn.Open();
            rowsInserted = cmd.ExecuteNonQuery();
            conn.Close();
            cmd = null;

        }

        return string.Format("Congrats, {0} row has been updated", rowsInserted);
    }

}

Note: To allow this Web Service to be called from script, using ASP.NET AJAX,you should uncomment the following line.

[System.Web.Script.Services.ScriptService]

6. Now make your insertdata.aspx as start page. run it , then u get :

5

7. Fill up the fields and click submit:

6

8. Now your table will contain the data that you entered.

7

9. You can even make insertdatajson.asmx as start page, then you can directly fill the data from it.
1

on clicking ReceiveWebservice, you get screen like:

2

After you click invoke option, data gets inserted into the database.

3

Now your table appears as:

4

You can call above asp web service from any other platforms like iphone, android.

Download above sample application Here

How to use Scroll View in Xcode

i am going to show you all how to use scroll view in xcode and make it work.

1. Create single view application
Screen Shot 2014-11-01 at 8.40.34 PM

2. Enter your application name
Screen Shot 2014-11-01 at 8.44.04 PM

3. click next selecting the appropriate device
4. select the application name and unselect the device orientation landscape left and landscape right

Screen Shot 2014-11-01 at 8.47.01 PM

Screen Shot 2014-11-01 at 8.47.20 PM

Screen Shot 2014-11-01 at 8.47.31 PM

5.click on the view controller then go to the first tab (file inspector), then unselect “use Auto Layout”

Screen Shot 2014-11-01 at 8.55.44 PM

6. Similarly go to the fourth tab (simulated Metrics), select the size as freeform.

Screen Shot 2014-11-01 at 8.57.58 PM

7. Now click on the view just below the view controller , select the measurement tab on the right hand side, then increase the height and fix the width as per your requirement.

Screen Shot 2014-11-01 at 9.01.44 PM

8. Now using the object library, drag the scroll view to the storyboard within view.

Screen Shot 2014-11-01 at 9.05.23 PM

9. Now go to viewcontroller.h and add the following code for scrollview

@interface ViewController : UIViewController
{
    IBOutlet UIScrollView *scroller;
}
@end

You can view above code in below image:

Screen Shot 2014-11-01 at 9.15.19 PM

10. Now go to viewcontroller.m and within viewDidload enable scrollview to yes.

@interface ViewController ()

@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 568)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

Above code is shown clearly in the below image:

Screen Shot 2014-11-01 at 9.21.31 PM

Now you are almost done with the tutorial.

11. Now go to storyboard.
12. Add some controls like label at the top and extreme bottom to get scrollview effect.

Screen Shot 2014-11-01 at 9.26.34 PM

13. Now finally click on the view controller then go to the sixth tab (Connections inspector) , there you find the outlets defined earlier by us.

14. Now drag the scrollview outlet ie, scroller to the scrollview of the storyboard

15. Then finally you get scroller referencing view controller as shown in below figure.

Screen Shot 2014-11-02 at 12.52.22 AM

16. Now run the project and you get scrolling effect in your application

Enjoy Coding