ios - 无法从另一个 ViewController 调用方法

标签 ios objective-c uiviewcontroller

我正在尝试执行以下操作

 ReaderController *readerController =  [[[ReaderController alloc] init] autorelease];;
readerController.fileName = fileName;
[readerController handleSingleTap];

其中 handleSingleTap 是 ReaderController 中的一个方法,但我不能调用它..方法是下一个

 - (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
#ifdef DEBUGX
    NSLog(@"%s", __FUNCTION__);
#endif

    ReaderDocument *document = [ReaderDocument unarchiveFromFileName:SAMPLE_DOCUMENT];

    if (document == nil) // Create a brand new ReaderDocument object the first time we run
    {
        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; 
        NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:[[NSString stringWithFormat:@"%@",fileName] stringByAppendingPathExtension:@"pdf"]];



        [self checkAndCreatePList];
        NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:pListPath];

        [plistDict setValue: [NSString stringWithFormat:@"%@",fileName]  forKey:@"fileName"];
        [plistDict writeToFile:pListPath atomically: YES];



//      NSString *filePath = [[NSBundle mainBundle] pathForResource:path ofType:nil];

        document = [[[ReaderDocument alloc] initWithFilePath:path password:nil] autorelease];
    }

    if (document != nil) // Must have a valid ReaderDocument object in order to proceed
    {
        ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];

        readerViewController.delegate = self; // Set the ReaderViewController delegate to self

#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)

        [self.navigationController pushViewController:readerViewController animated:YES];

#else // present in a modal view controller

        readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentModalViewController:readerViewController animated:YES];

#endif // DEMO_VIEW_CONTROLLER_PUSH

        [readerViewController release]; // Release the ReaderViewController
    }
}

有什么问题,为什么我不能调用此方法,我需要一些详细信息,感谢您的帮助

最佳答案

嗯,这很简单,你做到了:

[readerController handleSingleTap];

什么时候你应该做:

[readerController handleSingleTap:yourRecognizer];

[readerController handleSingleTap:nil];

如果您未能通过识别器参数,您将在需要 handleSingleTap: 时发送一个 handleSingleTap 信号

关于ios - 无法从另一个 ViewController 调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7230036/

相关文章:

ios - 为什么实例化后立即调用dealloc?

ios - 如何在 UITableView 中创建单行 View 分隔符

ios - 接收UDP广播数据

ios - 将 UIMotionEffect 与 OpenGL ES 一起使用

objective-c - objective-c (ios)从远程服务器打开sqlite数据库

iphone - 如何在XCode(iOS SDK)中添加按钮到注释 View

ios - 协议(protocol)和委托(delegate)不访问方法

ios - 禁止分段控制段改变

ios - Devise with Facebook Omniauth - 如何使用 API 进行身份验证?

android - 为 Objective-c 和 java 函数创建一个 dll