title: changing data in table view on button clicked-iphone
body: <p>I am new for iPhone apps development.
  In my app when i clicked on search button ,i want to display record in table view.
  i m using array to change record in table view but its not working..please help</p>
  
  <h2>viewController.m</h2>
  
  <pre><code>-(IBAction) printButtonPressed : (id) sender
  {
      mylabel.text =keyfileld.text;
      UITableView *tableView ;
      NSIndexPath *indexPath;
      mylabel.text =keyfileld.text;
  
      NSString *post =[NSString stringWithFormat:@"username=%@",keyfileld.text];
      NSString *hostStr = @"http://demo.com/search_iphone.php?";
      hostStr = [hostStr stringByAppendingString:post];
      NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
      NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
  
      [states removeObjectForKey:@"1"];   
      [states removeObjectForKey:@"2"]; 
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];        
      }
  
      cell.textLabel.text = [datasource objectAtIndex:indexPath.row]; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  
      if(serverOutput)
      {
          NSArray *listItems = [serverOutput componentsSeparatedByString:@"#"];
          UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
                                                                delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
          [alertsuccess show];
          mylabel.text = serverOutput;
          NSMutableArray *stringArray = [[NSMutableArray alloc] init];
          int x=1;
          for (int i=0;i&lt;listItems.count; i++) 
          { 
              NSString *myString = [NSString stringWithFormat:@"%d",x];
              NSArray *listItemsid = [[listItems objectAtIndex:i] componentsSeparatedByString:@","];
              NSLog(@"place name at index %d: %@\n", i, [listItemsid objectAtIndex:1]); 
              [states setObject:[listItemsid objectAtIndex:1] forKey:myString];
              x++;
              [stringArray insertObject:[NSMutableArray arrayWithObjects:str,nil] atIndex:i];         
          } 
  
          datasource = [states allKeys];
  
      } else {
          UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
                                                                delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
          [alertsuccess show];
  
          // [alertsuccess release];
      }
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
      UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }
  
      id aKey = [datasource objectAtIndex:indexPath.row]; 
      cell.textLabel.text = [states objectForKey:aKey];
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
  
      return cell;
  }
  </code></pre>