【发布时间】:2015-12-14 11:00:16
【问题描述】:
我刚刚将 xCode 更新到 7.0。我的代码以前可以工作,但现在我得到了:
CGContextSaveGState:无效的上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。
在我的应用程序中,我有一个收件箱,一旦选择了消息单元格,就会显示图像/视频。在消息显示正常之前,但在更新后它们不再显示。这是一个有效的错误还是 Apple 错误?涉及的代码放在下面。
InboxTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
// mark message as read
NSMutableArray *readByIds = [NSMutableArray arrayWithArray:[self.selectedMessage objectForKey:@"readBy"]];
if ([readByIds containsObject:[[PFUser currentUser] objectId]]) {
// message has already been read. do nothing
}else {
// message was unread. mark it as read now.
[readByIds addObject:[[PFUser currentUser] objectId]];
[self.selectedMessage setObject:readByIds forKey:@"readBy"];
[self.selectedMessage saveInBackground];
}
NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"]) {
// file type is image
[self performSegueWithIdentifier:@"showImage" sender:self];
} else {
// file type is video
PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
self.moviePlayer.contentURL = fileUrl;
[self.moviePlayer prepareToPlay];
[self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];
// add it to the view controller so we can see it
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
}
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showLogin"]) {
LoginViewController *lvc = (LoginViewController *)segue.destinationViewController;
[lvc setHidesBottomBarWhenPushed:YES];
lvc.navigationItem.hidesBackButton = YES;
//[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
} else if ([segue.identifier isEqualToString:@"showImage"]) {
ImageViewController *ivc = (ImageViewController *)segue.destinationViewController;
[ivc setHidesBottomBarWhenPushed:YES];
ivc.message = self.selectedMessage;
}
}
ImageViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSString *senderName = [self.message objectForKey:@"senderFullName"];
self.navigationItem.title = senderName;
// download image from Parse.com
PFFile *imageFile = [self.message objectForKey:@"file"];
NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];
//set the image view to the message image
self.imageView.image = [UIImage imageWithData:imageData];
}
【问题讨论】:
-
你试过设置
CG_CONTEXT_SHOW_BACKTRACE变量吗? -
我该怎么做呢?
-
这也可能是一个错误。见this。
-
好的,谢谢。我报告了这个错误
-
要设置 CG_CONTEXT_SHOW_BACKTRACE,请转到 Edit Schemes... > Run > Arguments > Environment Variables。添加值为 1 的变量 CG_CONTEXT_SHOW_BACKTRACE。
标签: ios objective-c cgcontext xcode7