Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView点击事件_Ios_Objective C - Fatal编程技术网

Ios UICollectionView点击事件

Ios UICollectionView点击事件,ios,objective-c,Ios,Objective C,我在ViewController中创建了UICollectionView。My UiCollectionViewCell包含一个imageview和一个标签。看起来它在处理点击事件方面真的很糟糕。我需要点击很多次,然后它才会对点击做出反应。通常它只在双击时进行 - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { N

我在ViewController中创建了UICollectionView。My UiCollectionViewCell包含一个imageview和一个标签。看起来它在处理点击事件方面真的很糟糕。我需要点击很多次,然后它才会对点击做出反应。通常它只在双击时进行

- (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;
}


}
-(void)collectionView:(UICollectionView*)collectionView diddesceleitematindexpath:(nsindepath*)indepath
{
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错误:nil]编码:NSUTF8StringEncoding];
NSArray*playArray2=[PHPArray组件由字符串分隔:@.”;

如果([playArray2 count]您是否启用了标签和图像以供用户交互?

单击单元格时,您正在执行同步请求,这可能会导致您必须多次单击的“感觉”。我建议您将NSURLConnection同步请求更改为异步请求。如下所示:

[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);
     }
 }];
[NSURLConnection sendAsynchronousRequest:请求
队列:[[NSOperationQueue alloc]init]
completionHandler:^(NSURLResponse*响应,NSData*数据,NSError*错误)
{
如果(错误==nil)
{
NSString*PHPArray==[[NSString alloc]initWithData:数据编码:NSUTF8StringEncoding];
NSLog(@“从url接收的数据:%@”,PHPArray);

如果([playArray2 count]在此处发布代码..我已经在cellForItemAtIndexpath中完成了此操作。[cell.patternLabel setUserInteractionEnabled:YES];[cell.patternImageView setUserInteractionEnabled:YES];是否在单元格的内容视图中添加了标签和图像?是的,我已将其放入单元格内容视图中。我已将其放入自定义单元格内容视图中。您可以尝试使用performSelector:withObject:afterDelay仅在didSelect完成后运行选择代码