user3195388
user3195388

Reputation: 129

UICollectionView Tap events

i've created a UICollectionView inside a ViewController. My UiCollectionViewCell contains a imageview and a label. It seems like it is really bad at handling click events. i need to click a lot of times before it react for the click. often it only do it on double tap.

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{


    NSString *urlString2 =  [NSString stringWithFormat:@"http://ratemyplays.com/songs.php?listid=%d", indexPath.row];
    NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc]init];
    [request2 setTimeoutInterval:20.0];
    [request2 setURL:[NSURL URLWithString:urlString2]];
    [request2 setHTTPMethod:@"POST"];

    NSString *PHPArray = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];

    NSArray *playArray2 = [PHPArray componentsSeparatedByString:@"."];

    if ([playArray2 count] <2) {
        UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"This Playlist is empty!!" message:@"We're Currently modifying it" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alert2 show];
    } else {
        YouTubeTableViewController *youTubeTableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YouTubeTableViewController"];
        youTubeTableViewController.selectedRowValue=indexPath.row;
        [self.navigationController pushViewController:youTubeTableViewController animated:YES];
        youTubeTableViewController.titleName = scoreArray;
        youTubeTableViewController.playlistId = scoreArray2;
}


}

Is this normal behavior or am i missing something?

Upvotes: 0

Views: 931

Answers (2)

xicocaio
xicocaio

Reputation: 887

You are doing a synchronous request when the cell is clicked, and it may be causing this "feeling" that you have to click several times. I suggest you change the NSURLConnection synchronous request to an asynchronous one. Like this:

[NSURLConnection sendAsynchronousRequest:request
                                   queue:[[NSOperationQueue alloc] init]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {

     if (error == nil)
     {
         NSString *PHPArray = =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
         NSLog(@"data received from url: %@", PHPArray);
         if ([playArray2 count] <2) {
             UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"This Playlist is empty!!" message:@"We're Currently modifying it" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

             [alert2 show];
         } else {
             YouTubeTableViewController *youTubeTableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YouTubeTableViewController"];
             youTubeTableViewController.selectedRowValue=indexPath.row;
             [self.navigationController pushViewController:youTubeTableViewController animated:YES];
             youTubeTableViewController.titleName = scoreArray;
             youTubeTableViewController.playlistId = scoreArray2;
         }

     }
     else if (error != nil && error.code == NSURLErrorTimedOut)
     {
         NSLog(@"error code: %ld", (long)error.code);
     }
     else if (error != nil)
     {
         NSLog(@"error code: %ld", (long)error.code);
     }
 }];

Upvotes: 2

marco alves
marco alves

Reputation: 1717

Do you have your label and image enabled for user interaction?

Upvotes: 0

Related Questions