0

I have a detail view controller which is pushed when a row is selected in a table view. When in a session the first time a row is selected it works fine. But when in the same session any row is selected there is a black screen behind all the content in the detail view controller which is pushed. And the scrolling of the uitextview also does not work

-(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);
    }
}

enter image description here

enter image description here

Ravin Kohli
  • 143
  • 10

1 Answers1

1

Just try to set window color in didFinishLaunchWithOptions: method in you app delegate.

Srj0x0
  • 458
  • 3
  • 12