我剛更新xCode爲7.0。我的代碼工作之前,但現在我得到:xCode CGContextSaveGState:無效的上下文0x0錯誤
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'變量? – Adam
我該如何去做呢? –
它也可能是一個錯誤。請參閱[this](http://stackoverflow.com/a/31887785/730701)。 – Adam