[英]Black Screen in UIViewController behind the content
我有一個詳細信息視圖控制器,當在表視圖中選擇一行時,該控制器將被推送。 在會話中第一次選擇行時,它可以正常工作。 但是,在同一會話中選擇任何行時,在按下的詳細信息視圖控制器中所有內容后面都會出現黑屏。 並且uitextview的滾動也不起作用
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"selected");
NSDictionary *size = [[NSDictionary alloc] init];
size = [self sizeForLabelAtIndexPath:indexPath.row tableView:tableView andFeed:self.feedArray[indexPath.row]];
CGFloat sizes = ([size[@"messageHeight"] floatValue] + [size[@"nameHeight"] floatValue] + [size[@"imageHeight"] floatValue]);
sizes *= 1.05;
if (sizes<327) {
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}else{
CellDetailViewController *cdvc = [self.storyboard instantiateViewControllerWithIdentifier:@"FacebookDetail"];
cdvc.sizeDictionary = [self sizeForLabelAtIndexPath:indexPath.row tableView:tableView andFeed:self.feedArray[indexPath.row]];
cdvc.feed = self.feedArray[indexPath.row];
[self.navigationController pushViewController:cdvc animated:YES];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.91 alpha:1];
self.messageLabel = [[UITextView alloc] init];
self.imageView = [[UIImageView alloc] init];
self.nameLabel = [[UILabel alloc] init];
self.dateLabel = [[UILabel alloc] init];
self.cardView = [[UIView alloc] init];
self.nameLabel.text = @"DCE Speaks Up";
self.nameLabel.textColor = [UIColor colorWithRed:0.235 green:0.353 blue:0.588 alpha:1.00];
self.messageLabel.font = [UIFont fontWithName:@"Droid Sans" size:15];
self.messageLabel.editable = NO;
self.messageLabel.dataDetectorTypes = UIDataDetectorTypeAll;
self.messageLabel.scrollEnabled = true;
self.messageLabel.userInteractionEnabled = true;
self.messageLabel.backgroundColor = [UIColor whiteColor];
self.messageLabel.textColor = [UIColor colorWithRed:0.078 green:0.094 blue:0.137 alpha:1.00];
self.dateLabel.textColor = [UIColor colorWithRed:0.569 green:0.592 blue:0.639 alpha:1.00];
self.dateLabel.font = [UIFont fontWithName:@"ArialMT" size:10];
self.cardView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
// Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.view.backgroundColor = [UIColor colorWithWhite:0.91 alpha:1];
if(self.feed.message){
self.messageLabel.text = self.feed.message;
}else if (self.feed.story){
self.messageLabel.text = self.feed.story;
}
if (self.feed.imageURL) {
self.imageView.image = [UIImage imageNamed:@"black.png"];
UIActivityIndicatorView *activityIndicator;
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake((10 + self.view.bounds.size.width -20),( [self.sizeDictionary[@"nameHeight"] floatValue] + [self.sizeDictionary[@"messageHeight"] floatValue] + 25 +[self.sizeDictionary[@"imageHeight"] floatValue])/2, 40.0, 40.0);
[self.imageView addSubview: activityIndicator];
// This line starts the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// This line starts the activity indicator on the view
[activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
NSData *data= [NSData dataWithContentsOfURL:self.feed.imageURL];
self.image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image= self.image ;
[activityIndicator stopAnimating];
});
[UIApplication sharedApplication].networkActivityIndicatorVisible = false;
});
}
self.dateLabel.text = [self differenceStringFromDate:self.feed.date];
[self.view setTranslatesAutoresizingMaskIntoConstraints:false];
self.cardView.frame = CGRectMake(5, 5 + self.navigationController.navigationBar.frame.size.height, self.view.bounds.size.width - 10, [self.sizeDictionary[@"imageHeight"] floatValue]+ [self.sizeDictionary[@"messageHeight"] floatValue] + [self.sizeDictionary[@"nameHeight"] floatValue] + 20);
self.cardView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.cardView];
self.nameLabel.frame = CGRectMake(10, 15+ self.navigationController.navigationBar.frame.size.height, self.view.bounds.size.width, 51);
self.dateLabel.frame = CGRectMake(15, 45+ self.navigationController.navigationBar.frame.size.height, self.view.bounds.size.width, 25);
self.messageLabel.frame = CGRectMake(10, [self.sizeDictionary[@"nameHeight"] floatValue] + 20 + self.navigationController.navigationBar.frame.size.height, self.view.bounds.size.width - 20, MIN([self.sizeDictionary[@"messageHeight"] floatValue], self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height-[self.sizeDictionary[@"imageHeight"] floatValue]));
[self.view addSubview:self.messageLabel];
[self.view addSubview:self.dateLabel];
[self.view addSubview:self.nameLabel];
if (self.feed.imageURL) {
self.imageView.frame = CGRectMake(10, [self.sizeDictionary[@"nameHeight"] floatValue] + 35 + self.navigationController.navigationBar.frame.size.height + MIN([self.sizeDictionary[@"messageHeight"] floatValue], self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height-[self.sizeDictionary[@"imageHeight"] floatValue]) , self.view.bounds.size.width - 20, [self.sizeDictionary[@"imageHeight"] floatValue]);
[self.view addSubview:self.imageView];
NSLog(@"%f",self.imageView.frame.size.height);
}
}
只需嘗試在應用程序委托中的didFinishLaunchWithOptions:
方法中設置窗口顏色即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.