内容后面的 UIViewController 中的黑屏
Posted
技术标签:
【中文标题】内容后面的 UIViewController 中的黑屏【英文标题】:Black Screen in UIViewController behind the content 【发布时间】:2016-06-20 21:35:08 【问题描述】:我有一个详细视图控制器,当在表格视图中选择一行时会推送该控制器。在会话中第一次选择一行时,它工作正常。但是,当在同一个会话中选择任何行时,在被推送的详细视图控制器中的所有内容后面都会出现一个黑屏。而且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);
【问题讨论】:
这个帮助? ***.com/questions/22413193/… 不,问题还在于 uitextview 不工作 【参考方案1】:只需尝试在您的应用程序委托中的didFinishLaunchWithOptions:
方法中设置窗口颜色。
【讨论】:
它滚动的 uitextview 也不起作用 我可以看到 viewDidLoad 初始化方法吗? 我添加了viewdidload方法 看起来,您的表视图控制器已被释放。可以添加 didSelectRowAtIndexPath 吗? 你找到解决方案了吗?以上是关于内容后面的 UIViewController 中的黑屏的主要内容,如果未能解决你的问题,请参考以下文章
如何将子视图添加到 UIViewController 将 UINavigationBar 推到后面
尝试在其视图不在窗口层次结构中的 UIViewController 上呈现 UIViewController