Ios 从视图中推送视图控制器

Ios 从视图中推送视图控制器,ios,objective-c,Ios,Objective C,您好,我正在开发一个应用程序,其中我使用了一个名为CFCoverFlowView的第三方库(无法链接它,但如果您只是谷歌CFCoverFlowView,您将找到GitHub站点) 我想完成的是,当单击不同的图像时,能够推动Septit ViewController。我使用故事板,所以我想使用 instantiateViewControllerWithIdentifier:@"" 在库中,单击图像时可以使用以下行: - (void)coverFlowView:(CFCoverFlowView *

您好,我正在开发一个应用程序,其中我使用了一个名为CFCoverFlowView的第三方库(无法链接它,但如果您只是谷歌CFCoverFlowView,您将找到GitHub站点)

我想完成的是,当单击不同的图像时,能够推动Septit ViewController。我使用故事板,所以我想使用

instantiateViewControllerWithIdentifier:@""
在库中,单击图像时可以使用以下行:

- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
我这样做是为了确保它与
UIAlertView
一起工作:

- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
{

if (index == 0)
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"0" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

}

if (index == 1)
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"1" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

}

if (index == 2)
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"2" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

}

if (index == 3)
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"3" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

}

if (index == 4)
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"4" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

    }

}
这是可行的,当我点击单独的图片时,我得到了这个(因为这是我在这里的第一个问题,我不能发布图片或超过2个链接,因为我的声誉很低。)

图1 图2

我想做的是当点击一个图像时,一个带有
故事板ID的
ViewController
被推送

当我尝试此操作时,应用程序崩溃:

- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
{
    if (index == 0)
    {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
    UIViewController *ViewController1 = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
    [self.navigationController pushViewController:ViewController1 animated:YES];
    }
}

因此,如果有人能帮助我,我将不胜感激,如果有什么遗漏或您不理解我的代码注释,我将编辑文本。

这是打字错误还是您没有推送您实例化的ViewController实例?您需要按一下ViewController1:


[self.navigationController-pushViewController:ViewController1-animated:YES]

假设:您得到了这个错误

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main.storyboard'
解决方案:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

尝试[storyboardWithName:@“Main”]而不是[storyboardWithName:@“Main.storyboard”]。还有,崩溃报告说了什么?但是我的故事板的名字是Main.storyboard,所以我想这就是我写的?这里是错误代码int Main(int argc,char*argv[]){@autoreleasepool{return UIApplicationMain(argc,argv,nil,NSStringFromClass([DEMOAppDelegate class]);}这不是错误代码。请启用异常断点。情节提要的名称是“Main”,而不是“Main.storyboard”。(好吧,实际上你是对的,但是。故事板是它的扩展,而不是它的“名字”)。我刚才看到了那个,我编辑了它,因为它是一个打字错误。你的导航控制器可能是零吗?方法
didSelectPageItemAtIndex
是在UIViewController内还是在UITableViewCell内?我不确定,但CFCWoverflowView是在UIViewController内的UIView。这些方法是在UI线程上激发的吗?您是否尝试过将代码包装在以下内容中:
dispatch\u async(dispatch\u get\u main\u queue(),^{})