我有一个详细视图控制器,当在表视图中选择一行时,该控制器被推送。在会话中第一次选择一行时,它可以正常工作。但是当在同一会话中选择任何行时,在推送的详细视图控制器中的所有内容后面都有黑屏。并且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);
}
}
答案 0 :(得分:1)
尝试在app appate中的didFinishLaunchWithOptions:
方法中设置窗口颜色。