- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道这个问题之前已经被问过,我花了很多时间遵循各种线程中的建议,不仅仅是在这个网站上,但没有结果。
我正在为 iPad 开发一个由多个 View 组成的应用程序。这些 View 中的每一个都包含一个 UITableView。某些 TableView 单元格包含使用 UITableViewCell 实现的自定义单元格。现在的问题是,我可以在 iPad 模拟器上毫无问题地运行我的应用程序,但不能在实际设备上运行。在设备上 - 一旦我尝试访问包含相关定制 UITableViewCell 的 View ,它就会崩溃并显示以下消息:
2011-08-03 20:37:13.849 myApp[658:707] Creating cell: LabledTextFieldCell.xib
2011-08-03 20:37:13.866 myApp[658:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/B9A24738-FA19-4A54-8CE5-813B48E6871E/iCockpit-Client.app> (loaded)' with name 'LabledTextFieldCell.xib''
我检查了一遍又一遍,一切似乎都井然有序。该文件存在于 Xcode 中以及物理上的文件系统中,并且在代码中以其正确的名称引用它。
这是发生崩溃的代码行:
[[NSBundle mainBundle] loadNibNamed:MyIdentifier owner:self options:nil];
在更大的背景下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
int curRow = indexPath.row;
int i = 0;
if (indexPath.section > 0) {
while (i < indexPath.section) {
curRow = curRow + [self sectionSize:i];
i++;
}
}
UITableViewCell *cellRet;
if (indexPath.section == 1) {
// code
} else if (indexPath.section == 2) {
// ...
} else if (indexPath.section == 3) {
static NSString *MyIdentifier = @"LabledSwitchCell";
NSLog(@"Creating cell: %@", MyIdentifier);
cellRet = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cellRet == nil) {
// CRASHES
// -------
[[NSBundle mainBundle] loadNibNamed:MyIdentifier owner:self options:nil];
// -------
cellRet = self.cell;
self.cell = nil;
}
// more code...
}
可能值得注意的是: Nib 最初是通过 File -> New -> New File...、Cocoa Touch -> UIViewController 子类添加的,它提供了三个文件 - MyClassViewController.m、MyClassViewController.h 和 MyClassViewController.xib 。我已将 MyClassViewController.xib(在我的实际情况下为 LabledTextfieldViewController.xib)重命名为 MyClassView.xib (LabledTextfieldView.xib),这对我来说似乎更符合逻辑。
如上所述,该应用程序在模拟器中运行良好,问题仅出现在实际设备上。
我的 Xcode 版本是最新的 Xcode 4.1(Build 4B110)。
提前致谢。非常感谢任何帮助!
最佳答案
检查 NIB 文件名的拼写,尤其是大小写。
我相信模拟器文件系统不区分大小写,但实际设备是。
关于objective-c - iPad 应用程序仅在设备上而非模拟器上加载 Nib 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6931886/
我是一名优秀的程序员,十分优秀!