ios - 找不到 NSBundle mainBundle

标签 ios xcode nsbundle mainbundle

我在 iPad 上使用 Split View模板。

在我的 MasterViewController代码:

NSBundle * bundle = [NSBundle mainBundle];

有效。

在我的 DetailViewController相同的代码显示错误?我导入了<UIKit/UIKit.h> .它知道NSBundle但不认识mainBundle无论出于何种原因。

如果是这样就好了。可以帮助我!

Error

Missing "[" at start of message send expression

编辑

回答:

我忘记了括号。它在案例陈述中。所以使用:

case 1:
{
   //bla ...
}

最佳答案

在声明变量的 case 语句中,语句周围需要大括号,这只是简单的“C”语法。

固定:

switch (sender.row) {
    case 1:
    {
        NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testclip" ofType:@"mov"]];
        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    }
}

我将 MoviePlayerController 更改为 MPMoviePlayerController 假设这就是操作的意思。我还添加了缺少的 player 变量。

关于ios - 找不到 NSBundle mainBundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8551514/

相关文章:

iphone - 如何在 iOS 应用程序中实现互斥量

ios - 如何从MetricKit触发有效负载进行开发和调试

ios - NSBundle pathForResource返回nil?

ios - 使用 Swift 获取版本和构建信息

xcode - 对于 "Working copy not locked; this is probably a bug, please report"SVN 错误我该怎么办?

ios - 如何检查 Storyboard 是否存在于特定的 NSBundle 中

ios - 为什么单元格有效但创建后其元素为零

ios - 将 JSON 提取到 NSArray 中以进行动态导航

swift - 在 Plist 中检索用户定义的值

c++ - Xcode:如何在 i7 上为旧版 Intel 处理器(i5、Core 2 Duo)构建