In my widget extension, I have only the following code that gets called when the widget appears, nowhere in the code, am I adjusting the frame or hidden properties of _imageView. However, every time this code is executed, the code works fine and does what it is supposed to, but the _imageView disappears. At first I thought that the _imageView was being removed from the view somehow, so then I added a log to log out the frame of the _imageView, to check. The logs come back fine.
I then found out that if I were to scroll through notification center to where the widget is no longer showing, and then scroll back, where I can then see my widget again, the imageView is back, no problem.
Why is the _imageView "disappearing," when this code is being executed?
if (copiedString && ![textArray containsObject:copiedString]) {
NSLog(@"String was found, and string hasn't been added before.");
NSLog(@"Image view frame, is it still there? %@", NSStringFromCGRect(_imageView.frame));
[textArray addObject:copiedString];
[defaults setObject:textArray forKey:@"array"];
[defaults synchronize];
} else {
NSLog(@"Nothing interesting here, contents of clipboard: string: %@ image: %@", copiedString, copiedImage);
NSLog(@"Image view frame, is it still there? %@", NSStringFromCGRect(_imageView.frame));
[defaults setObject:imageArray forKey:@"imagesArray"];
[defaults synchronize];
}
[_tableView reloadData];
if (imageArray.count != 0 && self.imageFunctionalityEnabled) {
if (![defaults boolForKey:@"autoAdd"]) {
if (textArray.count <= 5) {
self.preferredContentSize = CGSizeMake(0, 199 + textArray.count * 43.5);
} else if (textArray.count >= 5) {
self.preferredContentSize = CGSizeMake(0, 199 + 217.5);
}
} else {
if (textArray.count <= 5) {
self.preferredContentSize = CGSizeMake(0, 155 + textArray.count * 43.5);
} else if (textArray.count >= 5) {
self.preferredContentSize = CGSizeMake(0, 155 + 217.5);
}
}
} else {
if (![defaults boolForKey:@"autoAdd"]) {
if (textArray.count <= 5) {
self.preferredContentSize = CGSizeMake(0, 44 + textArray.count * 43.5);
} else if (textArray.count >= 5) {
self.preferredContentSize = CGSizeMake(0, 44 + 217.5);
}
} else {
if (textArray.count <= 5) {
self.preferredContentSize = CGSizeMake(0, 0 + textArray.count * 43.5);
} else if (textArray.count >= 5) {
self.preferredContentSize = CGSizeMake(0, 0 + 217.5);
}
}
}
[defaults setInteger:[UIPasteboard generalPasteboard].changeCount forKey:@"changeCount"];
}