-[UIPickerView setFrame:]: invalid height value 200.0 pinned to 180.0
i got this error in nslog. but i do not care about it .
any crash is possible in future ? . my coding is
pickerviewdropdown.Dropoption = [[Utility getSizeValues] mutableCopy];
[pickerviewdropdown.pickerview reloadAllComponents];
subOptionPopOver = [[UIPopoverController alloc] initWithContentViewController:pickerviewdropdown];
[subOptionPopOver setPopoverContentSize:CGSizeMake(200, 200)];
[subOptionPopOver presentPopoverFromRect:[sender bounds]
inView:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:NO];
Its obvious that you are setting the height to 200 when it should be 180. There will not be a crash but I suggest you change your code to CGSizeMake(200, 180) so you don't keep getting that error.
Related
I pulled this code from a reputable tutorial, and I get a NaN error on the CGFloat instance *imageHeight when I run the application. However, if I change the type to NSUInteger, the app builds out just fine. Is there anyone who could potentially explain whats happening. I understand the NaN = Not A Number, but CGFloat should work fine as the data type.
Crashes
CGFloat imageHeight = self.mediaItem.image.size.height / self.mediaItem.image.size.width * CGRectGetWidth(self.contentView.bounds);
self.mediaImageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), imageHeight);<--NaN ERROR is thrown here
Does Not Crash
NSUInteger imageHeight = self.mediaItem.image.size.height / self.mediaItem.image.size.width * CGRectGetWidth(self.contentView.bounds);
self.mediaImageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), imageHeight);
Full method body
- (void) layoutSubviews {
[super layoutSubviews];
NSUInteger imageHeight = self.mediaItem.image.size.height / self.mediaItem.image.size.width * CGRectGetWidth(self.contentView.bounds);
self.mediaImageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), imageHeight);
CGSize sizeOfUsernameAndCaptionLabel = [self sizeOfString:self.usernameAndCaptionLabel.attributedText];
self.usernameAndCaptionLabel.frame = CGRectMake(0, CGRectGetMaxY(self.mediaImageView.frame), CGRectGetWidth(self.contentView.bounds), sizeOfUsernameAndCaptionLabel.height);
CGSize sizeOfCommentLabel = [self sizeOfString:self.commentLabel.attributedText];
self.commentLabel.frame = CGRectMake(0, CGRectGetMaxY(self.usernameAndCaptionLabel.frame), CGRectGetWidth(self.bounds), sizeOfCommentLabel.height);
// Hide the line between cells
self.separatorInset = UIEdgeInsetsMake(0, CGRectGetWidth(self.bounds)/2.0, 0, CGRectGetWidth(self.bounds)/2.0);
}
The only likely way that you could get a NaN there is by computing 0 / 0, so I deduce that the height and width members of self.mediaItem.image.size are probably both zero. That is, self.mediaImage.image.size is probably CGSizeZero.
Note that if self.mediaItem is nil, or if self.mediaItem.image is nil, then self.mediaItem.image.size returns CGSizeZero. My guess is one of those is nil.
You can easily check this. Either put a breakpoint in layoutSubviews, or add an NSLog at the top of it:
NSLog(#"layoutSubviews: mediaItem=%p image=%p size=%#",
self.mediaItem, self.mediaItem.image,
NSStringFromCGSize(self.mediaItem.image.size));
I have a TableViewController with a UIActivityIndicatorView as a subview while the content loads and it works like it should. The only problem is that I can't get the activity indicator centered on the screen.
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
loadingIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(width / 2, height / 2, 125, 125)];
loadingIndicator.center = CGPointMake(width / 2, height / 2);
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
loadingIndicator.hidesWhenStopped = YES;
[self.tableView addSubview:loadingIndicator];
[loadingIndicator startAnimating];
Also worth noting, the large indicator seems to be shifted 3 pix left and up. (swift, iOS 9.2.1)
Maybe its because your view is of wrong size in xib(say, its for iPhone 5 in xib and you are running it on iPhone 6 ).
So, your height and width calculation is wrong.
Instead, try using
CGFloat width = CGRectGetWidth(UIScreen.mainScreen.bounds);
CGFloat height = CGRectGetHeight(UIScreen.mainScreen.bounds);
Hope it helps :)
Try the Code :
CGFloat width = CGRectGetWidth(self.tableView.bounds);
CGFloat height = CGRectGetHeight(self.tableView.bounds);
UIActivityIndicatorView *loadingIndicator;
loadingIndicator = [[UIActivityIndicatorView alloc]init];
loadingIndicator.center = CGPointMake(width / 2, height / 2);
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
loadingIndicator.hidesWhenStopped = YES;
[self.tableView addSubview:loadingIndicator];
[loadingIndicator startAnimating];
Try
[loadingIndicator setCenter:[self.tableView center]];
try by change this line loadingIndicator.center = CGPointMake(width / 2, height / 2); to loadingIndicator.center = self.view.center; and add the subviewloadingIndicator to self.view
Your code is perfect, but I think you set frame on basic of self.view and added that indicator on tableview.
so add that indicator on self.view.
If your problem is that the position is not correct horizontally, it may be that view's bounds is still the freedom width from your storyboard.
Try to put your code in viewDidLayoutSubviews. To avoid repeated adding to the view, set the activityObject as a property of this class.
Tejvansh Singh Chhabra's answer is good when you want to center in the screen. Just when generally if you want to position view based on view's frame or bounds, put code after viewDidLayoutSubviews stage, or add constraints to the view.
I've got a UICollectionView that takes the whole of the screen. The UICollectionView has cells as big as the UICollectionView itself, and I use paging.
On rotation of the device I want the cells to adjust their size to the new UICollectionView size. I currently achieve this by interchanging a layout object in willAnimateRotationToInterfaceOrientation::
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_collectionView setCollectionViewLayout:[self collectionViewFlowLayoutForOrientation:toInterfaceOrientation] animated:YES];
}
with collectionViewFlowLayoutForOrientation: being as follows:
- (UICollectionViewFlowLayout *)collectionViewFlowLayoutForOrientation:(UIInterfaceOrientation)orientation
{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
CGFloat width = UIInterfaceOrientationIsLandscape(orientation) ? MAX(screenSize.width, screenSize.height) : MIN(screenSize.width, screenSize.height);
CGFloat height = UIInterfaceOrientationIsLandscape(orientation) ? MIN(screenSize.width, screenSize.height) : MAX(screenSize.width, screenSize.height);
UICollectionViewFlowLayout *collectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[collectionViewFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[collectionViewFlowLayout setItemSize:CGSizeMake(width, height)];
[collectionViewFlowLayout setMinimumLineSpacing:0.0f];
[collectionViewFlowLayout setSectionInset:UIEdgeInsetsZero];
[collectionViewFlowLayout setMinimumInteritemSpacing:0.0f];
return collectionViewFlowLayout;
}
It doesn't work as intended.
First of all, I get a message in the console indicating I probably am doing something not entirely legitimate:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.
It is a fair message, as starting the animation to rotate, the screen / UICollectionView still has the frame for the old orientation. I'd be inclined to abide it.
Secondly, the contentOffset is incorrect after rotation as it doesn't get recalculated.
I've seen other solutions which just invalidate the layout in willRotateToInterfaceOrientation:duration:, but this doesn't recalculate the contentOffset either. I followed it up by changing the contentOffset and contentSize as follows, but the result is not perfect either:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGSize fromCollectionViewSize = [self collectionViewSizeForOrientation:[self interfaceOrientation]];
CGSize toCollectionViewSize = [self collectionViewSizeForOrientation:toInterfaceOrientation];
CGFloat currentPage = [_collectionView contentOffset].x / [_collectionView bounds].size.width;
NSInteger itemCount = [_collectionView numberOfItemsInSection:0];
UICollectionViewFlowLayoutInvalidationContext *invalidationContext = [[UICollectionViewFlowLayoutInvalidationContext alloc] init];
[invalidationContext setContentSizeAdjustment:CGSizeMake((toCollectionViewSize.width - fromCollectionViewSize.width) * itemCount, toCollectionViewSize.height - fromCollectionViewSize.height)];
[invalidationContext setContentOffsetAdjustment:CGPointMake(currentPage * toCollectionViewSize.width - [_collectionView contentOffset].x, 0)];
[[_collectionView collectionViewLayout] invalidateLayoutWithContext:invalidationContext];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
So, my question is: What solution gives the intended result?
Try adding the line
[_collectionView invalidateIntrinsicContentSize] just before you set your layout. This should cause it to re-calculate the layout, and, hopefully get rid of your warning message.
I have an expandable UITableView, which can expand/collapse when users press a button.
The way is that I change its content when the button is pressed, and assign the contentSize.height to the height of the tableview. It works properly in iOS 6.
However, in iOS 7, no matter what value I set to the height of the tableview, it displays like the height is never changed and the new content is cut off. The height seems to stick to the origin height in the storyboard. But if I print the height of the tableview, it's right the value I set.
Here is how I change its height:
//Do some change to the content...
[tableview reloadData];
NSLog(#"height: %f, contentHeight: %f", tableview.frame.size.height, tableview.contentSize.height);// print height: 60, contentHeight: 160
CGRect frame = tableview.frame;
frame.size.height = tableview.contentSize.height;
tableview.frame = frame;
NSLog(#"height: %f, contentHeight: %f", tableview.frame.size.height, tableview.contentSize.height);// print height: 160, contentHeight: 160
Any ideas?
p.s. The tableview is in a UIScrollView. (if it matters.)
I think your problem is the scrollview.
try something like this:
CGRect screen = [[UIScreen mainScreen] bounds];
CGSize scrollViewContentSize = CGSizeMake(screen.size.width, screen.size.height);
[self.scrollView addSubview:tableview];
scrollViewContentSize.height += tableview.frame.size.height;
[self.scrollView setContentSize:scrollViewContentSize];
[self.view addSubview:self.scrollView];
I'm debugging a strange text wrapping problem on my device that I have tracked down to some kind of modification in the UITextView contentInset value starting in XCode 4.
Here is the sample code I am using to showcase this bug:
NSString *message = #"How are you doing?";
CGSize messageDimensions = [message sizeWithFont:[UIFont systemFontOfSize:15.0]
constrainedToSize:CGSizeMake(self.view.frame.size.width,9999)
lineBreakMode:UILineBreakModeWordWrap];
CGFloat xOffset = 20;
CGFloat yOffset = 20;
CGRect textViewFrame = CGRectMake(xOffset, yOffset, messageDimensions.width+16, messageDimensions.height+16);
self.textView = [[[UITextView alloc] initWithFrame:textViewFrame] autorelease];
self.textView.font = [UIFont systemFontOfSize:15.0];
self.textView.text = message;
self.textView.editable = NO;
[self.view addSubview:self.textView];
Attached are two screenshots running code on the iOS 5 simulator and on my iPhone 4.
Here is the iPhone 4 running iOS5:
Here is the simulator running iOS5.0:
As you can see, it is wrapping in one but not the other. In order to prevent wrapping on my iOS4 device I have to change this line:
CGRect textViewFrame = CGRectMake(xOffset, yOffset, messageDimensions.width+16, messageDimensions.height+16);
To have a padding of +17 not +16.
Can anyone tell me if this is a known bug, and if the UITextView padding amount is a constant value somewhere in UIKit to which I can refer instead of hard-coding it?
Thanks!