objective-c - NSlogging 和 NSString 难题

标签 objective-c ios ipad uitableview

我对此还是比较陌生,因为这是我的第一个项目。但我对堆栈溢出社区充满信心,因为你们之前都曾帮助过我。

我有一个相当有趣的难题要问大家。我称标准:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

在我的 TableView 中让它推送一个 View Controller ,并更新字符串的值(下面的方法)(字符串中的更改是通过不同的方法进行 NSLogged 的​​):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
appDelegate.baseURL = nil;
musicInteractionController = [[xSheetMusicViewController alloc]init];
if (indexPath.row == 0 && indexPath.section == 0) {
    appDelegate.baseURL = @"mussette.pdf";
    [self.navigationController pushViewController:musicInteractionController animated:YES];
}
else if (indexPath.row == 1 && indexPath.section == 0) {
    appDelegate.baseURL = @"Importing PDF's.pdf";
    [self.navigationController pushViewController:musicInteractionController animated:YES];

}
else if (indexPath.row == 2 && indexPath.section == 0) {
   appDelegate.baseURL = @"Example.pdf";
    [self.navigationController pushViewController:musicInteractionController animated:YES];

}
else if (indexPath.section == 1) {
    appDelegate.baseURL = [[ivContentsList objectAtIndex:indexPath.row]lastPathComponent];
    [self.navigationController pushViewController:musicInteractionController animated:YES];

}
[musicInteractionController release]; musicInteractionController = nil;
appDelegate.baseURL = nil;

我的代码中没有错误、警告或内存泄漏。以及它由更新 View 以显示当前 PDF 的新 View Controller 读取的字符串更改。它工作正常,但会一遍又一遍地显示相同的 PDF,尽管 NSLog 值发生了变化。如果有帮助,我使用的是 iOS 模拟器,而不是真实设备。

这是推送第一个单元格之后的示例 NSLog,然后是第二个单元格(忽略 nil View Controller 日志,我认为这是一个错误。此外,向下的日志来自第二个 View 中的私有(private)方法,因此它也可以被忽略。对于那些能够解决 CGContextClipToRect: invalid context 0x0 警告的人来说,这是一个奖励:

 2011-09-15 16:24:23.731 SheetMuse[43068:b603] value - (null)
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGContextClipToRect: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGContextGetClipBoundingBox: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGContextConcatCTM: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGBitmapContextCreateImage: invalid context 0x0
2011-09-15 16:24:27.050 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c5e220>.
2011-09-15 16:24:27.069 SheetMuse[43068:b603] value - mussette.pdf
2011-09-15 16:24:27.072 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4e74620>.
2011-09-15 16:24:27.097 SheetMuse[43068:b603] value - mussette.pdf
2011-09-15 16:24:33.944 SheetMuse[43068:b603] Down
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextClipToRect: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextGetClipBoundingBox: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextConcatCTM: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGBitmapContextCreateImage: invalid context 0x0
2011-09-15 16:24:36.587 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c54bf0>.
2011-09-15 16:24:36.588 SheetMuse[43068:b603] value - Importing PDF's.pdf
2011-09-15 16:24:36.590 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c50790>.
2011-09-15 16:24:36.591 SheetMuse[43068:b603] value - Importing PDF's.pdf

提前致谢。

最佳答案

Here is a sample NSLog after pushing the first cell, then the second (ignore the nil view controller log, I think it's a bug. Also, the down Log is from a private method in the second view, so it can also be ignored. And a bonus to those who can resolve the CGContextClipToRect: invalid context 0x0 warning)

我知道人们很容易认为它们没有关系,但重要的是要记住, bug 就像雪球 - 它们开始滚动时会积聚更多的雪。

musicInteractionController = [[xSheetMusicViewController alloc]init];

日志似乎表明您的 musicInteractionController 为零。我还没有看到你的 xSheetMusicViewController 初始化代码(顺便说一句,我建议使用 Apple 对类和变量命名的建议:类以大写字母开头,变量以小写字母开头)我不能说为什么,但 UIViewController 的子类可能应该使用 - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle 进行初始化。

我的猜测是,如果您解决了 nil View Controller ,您将解决其他错误。

更新

From Apple's docs:

This is the designated initializer for this class.

The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad method and perform your tasks there.

If you specify nil for the nibName parameter, you must either override the loadView method and create your views there or you must provide a nib file in your bundle whose name (without the .nib extension) matches the name of your view controller class. (In this latter case, the class name becomes the name stored in the nibName property.) If you do none of these, the view controller will be unable to load its view.

因此,所有内容都需要在类的 loadView 方法中进行设置。您能告诉我们您是如何实现该方法的吗?

关于objective-c - NSlogging 和 NSString 难题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7438176/

相关文章:

iphone - 在 iOS 中,GestureRecognizer 目标操作是否在单独的线程中运行?

ios - 分机上的 "Undefined symbols for architecture arm64"

objective-c - 从动态实例化的类(objective-c)设置主视图 Controller 中的属性值

objective-c - Cocoa 始终以权限运行应用程序

ios - UISlider 停止时如何触发方法?

ios - 如何更改 SearchBar 边框颜色

ios - 仅在纵向模式下强制 UINavigationController

ios - [_UIWebViewScrollViewDelegateForwarder scrollViewWasRemoved :]: unrecognized selector sent to instance

css - 如何使用 CSS 转换在屏幕上滑动 div?

ios - UIActivityViewController 在设备上显示时崩溃