Question: I have created 5 buttons using for loop based on incrementing y axis value in `CGRectMake`. But how can i change the background color of button when i clicked each button?and also title AND having alertview for each button??pls suggest me answer..

```
//array taken for button titles
NSArray *array1=[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];

int k=0;  

for(int i=50;i<=350;i=i+70)
{
  button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
  button.frame=CGRectMake(30,i,35,40);
  [button addTarget:self action:@selector(buttonclicked:) forControlEvents:UIControlEventTouchUpInside];
  if (k<[array1 count])
  {
    [button setTitle:[array1 objectAtIndex:k] forState:UIControlStateNormal];
  }
  k++;  
  [self.view addSubview:button]; 
}

```

Answer: 
Plain old way !

Include:

```
#include <wininet.h>
#pragma comment(lib,"Wininet.lib")

```

In your Method:

```
char url[128];
strcat(url, "http://www.techtoolbox.com");
bool bConnect = InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0);

if (bConnect)
{
    //internet connection exists !
}
else
{
            //internet DOES NOT connection exists !
}

```

Hope it helps.
The best way to test the availability of any resource is to try to use it. You only care about the Internet if there is something out there you want to connect to. So, try to connect to it, in the normal course of your program, and handle the errors. Don't try to second-guess what might happen if you try. First, you're trying to predict the future. Second, you aren't necessarily exercising the same things that the actual connection would exercise. Third, your test may succeed and your subsequent use fail due to an intervening condition changing. Fourth, you have to handle the errors from the real use of the resource anyway: why write all that code twice?