Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here I am passing the values to the array.
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- CGPoint lastPoint = [touch locationInView:self.ColorPickerImageView];
- UIColor *color = [self getPixelColorAtLocation:lastPoint];
- if ([touch tapCount] == 2) {
- //self.imageView.image = nil;
- arrayOFPalette = [[NSMutableArray alloc] init];
- if (self.imgView1.backgroundColor == nil)
- {
- self.lbl1.text = hexsTring;
- self.imgView1.backgroundColor = color;
- }
- else if
- (self.imgView2.backgroundColor == nil)
- {
- self.lbl2.text = hexsTring;
- self.imgView2.backgroundColor = color;
- }
- else if (self.imgView3.backgroundColor == nil)
- {
- self.lbl3.text = hexsTring;
- self.imgView3.backgroundColor = color;
- }
- else if (self.imgView4.backgroundColor == nil)
- {
- self.lbl4.text = hexsTring;
- self.imgView4.backgroundColor = color;
- }
- else if (self.imgView5.backgroundColor == nil)
- {
- self.lbl5.text = hexsTring;
- self.imgView5.backgroundColor = color;
- }
- else
- {
- [self showErrorAlert];
- }
- [arrayOFPalette addObject:self.lbl1.text];
- [arrayOFPalette addObject:self.lbl2.text];
- [arrayOFPalette addObject:self.lbl3.text];
- [arrayOFPalette addObject:self.lbl4.text];
- [arrayOFPalette addObject:self.lbl5.text];
- return;
- }
- NSLog(@"%@",arrayOFPalette);
- NSLog(@"color is : %@",color);
- NSLog(@"%f",lastPoint.x);
- NSLog(@"%f",lastPoint.y);
- self.selectedColorView.backgroundColor = color;
- }
- And here is the button event.
- - (IBAction)btnSearchPalette:(id)sender {
- if (arrayOFPalette != nil) {
- // int myCount = 0;
- // while (myCount <= arrayOFPalette.count) {
- // NSLog(@"iteration %d",myCount);
- // myCount++;
- // NSString *indexValue = [arrayOFPalette objectAtIndex:0];
- // NSLog(@"index 0 have %@",indexValue);
- // if ([arrayOFPalette objectAtIndex:1] == [NSNull null])
- // {
- // NSLog(@"index is null");
- // }else{
- // NSLog(@"has value");
- // }
- // }
- NSURL *url = [NSURL URLWithString:@"http://localhost/ColorPicker/search.php"];
- NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
- NSString *messageBody = [NSString stringWithFormat:@"color=%@",arrayOFPalette];
- // if I just send a single value e.g; #ff88bc the api respond fine
- NSData *postData = [messageBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
- NSString *msgLength = [NSString stringWithFormat:@"%d", [postData length]];
- [theRequest setHTTPMethod:@"POST"];
- [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
- [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- [theRequest setHTTPBody:postData]; //[color dataUsingEncoding:NSUTF8StringEncoding]];
- NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
- if(theConnection)
- {
- NSLog(@"Connection Successful");
- NSURLResponse *response;
- NSError *err;
- NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
- // NSLog(@"responseData here is: %@", responseData);
- NSString *resPonseGot = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
- NSLog(@"Response ==> %@", resPonseGot);
- NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- imgURLArray =[str componentsSeparatedByString:@","];
- }
- // here I am passing result array containing url of images to the other array and sending to the gallery so that they can be viewed
- ViewController *customImageGallery = [[ViewController alloc] init];
- customImageGallery.imgArrayfromURL = imgURLArray;
- if (imgURLArray != nil) {
- [self.navigationController pushViewController:customImageGallery animated:YES];
- }
- else{
- [self alertStatus:@"Sorry No Matching Found" :@"Sorry!"];
- }
- }
- else{
- UIAlertView *ArrayAlert = [[UIAlertView alloc] initWithTitle:@"Empty Palette"
- message:@"Please Select Some Colors" delegate:nil
- cancelButtonTitle:nil
- otherButtonTitles:@"OK", nil];
- [ArrayAlert show];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment