UICollectionViewCell hidden though I never set it hidden - objective-c

I'm quite amazed by the result I get from those lines:
[cell setHidden:NO];
NSLog(#"CELL = %#", cell);
NSLog(#"HIDDEN = %hhd", cell.hidden);
Output:
2015-06-13 19:35:53.923 CELL = <DetailedSqeedCollectionViewCell: 0x145660b0; baseClass = UICollectionViewCell; frame = (-20 -49; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x1582cd90>>
2015-06-13 19:35:53.923 HIDDEN = 1
How is it possible, does anyone have a clue?
Thanks in advance.

I had this problem. iOS is smart enough to hide cells if the underlying subviews, in my case the imageView's frame was outside the bounds and not showing. Make sure if any subviews you have are set properly.
You will also find that if you set the background cell color to something that does not match the UICollectionView, it will not be shown hidden anymore.

Related

tableView's content offset changes automatically if canFocusRowAtIndexPath is set to NO

Problem: Scrolling to top again to tableView changes content offset and it hides first tableView cell.
I know there are lot of post on scrolling issue with tableView's scrollView where tableView content offsets changes after scrolling but there solution didn't helped me.
I tried to set content offset to 0 in -(void)layoutSubviews method but doesn't help. Also, this doesn't help.
self.automaticallyAdjustsScrollViewInsets = NO;
self.parentViewController.automaticallyAdjustsScrollViewInsets = NO;
In Detail:
When tableView loads, I see content offset set to {0, 0}
Printing description of $6:
<UITableView: 0x7fca15828400; frame = (0 0; 1920 1080); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x60800024cb40>; layer = <CALayer: 0x60800022c780>; contentOffset: {0, 0}; contentSize: {1920, 1600}>
when I scroll down, and top to again, I see offset content changed.
Printing description of $10:
<UITableView: 0x7fca14880400; frame = (0 0; 1920 1080); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x618000056da0>; layer = <CALayer: 0x618000037920>; contentOffset: {0, 108}; contentSize: {1920, 3754}>
However, I set canFocusRowAtIndexPath to YES, I don't see problem with scrollView but I don't want tableViewCell to focused.
- (BOOL)tableView:(UITableView *)tableView canFocusRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
Any help please?
This issue was because UICollectionViewFlowLayout which I was setting programmatically and messing with content offset every time when tableView's cellForRowIndexpath is getting called.

Getting the image from a UIButton

I'm trying to get the image assigned to a button on click, so I can assign it to something else when the button is clicked.
I think I'm nearly there, I've managed to get the following info from the button
Sender info is: <UIImageView: 0x757d9b0; frame = (0 0; 100 100); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757da10>> - image-name.png
As you can see, the image name is appended at the end of the log but I'm not sure how to get just that.
The code I've used to get this is:
sender.imageView
Thanks in advance for any help
EDIT:
Thanks to #zoul for leading me on the right path.
I ended up doing the following:
UIImage *image = [sender imageForState:UIControlStateNormal];
[self.newButton setImage:image forState:UIControlStateNormal];
There’s an imageForState: method on UIButton.

UICollectionView column grid gaps

I am using UICollectionView flow layout in my iPad application. I have cells with different width and heights. When I used subclass of UICollectionViewFlowLayout as layout for collection view, it shows me gaps between cells.
If there is large cell in column, it makes grid and small cells of that column get render centered of that large cell in column. Is there any better way to tight cell wrapping?
I am using horizontal scrolling. I tried using layoutAttributesForElementsInRect: method, but didn't get succeed into that.
Please let me know if anyone has done same kind of thing by using layoutAttributesForElementsInRect: method or by other way...
Please find attached image. I need same kind of solution
Thanks in advance...
Use like this
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 2;
I subclassed UICollectionViewFlowLayout and in both my layoutAttributesForItemAtIndexPath: and layoutAttributesForElementsInRect: methods I have one method called
setLineAttributes:(UICollectionViewLayoutAttributes *)attributes visibleRect:(CGRect)visibleRect:
which contains:
if (attributes.indexPath.item == 0 || attributes.indexPath.item == 1 || attributes.indexPath.item == 2) {
CGRect f = attributes.frame;
f.origin.x = 0;
attributes.frame = f;
} else {
NSIndexPath *ipPrev = [NSIndexPath indexPathForItem:attributes.indexPath.item - 3 inSection:attributes.indexPath.section];
CGRect fPrev = [self layoutAttributesForItemAtIndexPath:ipPrev].frame;
CGFloat rightPrev = fPrev.origin.x + fPrev.size.width + 10;
if (attributes.frame.origin.x <= rightPrev)
return;
CGRect f = attributes.frame;
f.origin.x = rightPrev;
attributes.frame = f;
}

UITableViewCell curve line anomaly- left side. What's causing this? Image included

I have this odd semicircle being drawn at the top left of each cell in this Table View. I can't seem to be able to get rid of it. I'm not doing any custom drawing in my cells, although the cells are all subclasses of UITableViewCell.
The curved artifact appears only in the first cell in each section, and is still persistent regardless of the table view background.
This is all the custom code in the cell, the rest is in IB
- (void)layoutSubviews {
// NSLog(#"DataEntryCell layoutSubviews");
UILabel *topLabel = [self parameterLabel];
UILabel *bottomLabel = [self dataLabel];
topLabel.font = [UIFont boldSystemFontOfSize:18.0];
topLabel.textAlignment = UITextAlignmentCenter;
topLabel.textColor = [UIColor darkGrayColor];
topLabel.shadowColor = [UIColor lightGrayColor];
topLabel.shadowOffset = CGSizeMake(0.0, 1.0);
bottomLabel.font = [UIFont systemFontOfSize:16.0];
bottomLabel.textAlignment = UITextAlignmentLeft;
bottomLabel.textColor = [UIColor darkGrayColor];
bottomLabel.numberOfLines = 0;
bottomLabel.lineBreakMode = UILineBreakModeWordWrap;
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.autoresizesSubviews = YES;
}
Any idea what could causing this?
Thanks
I don't see anything in that layoutSubviews that really belongs there. All of those properties on the labels should be set when the labels are created. Ditto for the properties on self. The selectionStyle in particular seems suspicious since it mentions gray and you have a stray gray line. By the time layoutSubviews is called, it's too late to set autoresizesSubviews; autoresizing happens before you receive layoutSubviews.
Try putting that stuff closer to the cell's initialization - in awakeFromNib if you're loading the cell (and its subviews) from a nib, or with the code that creates and adds the subviews.

autoresize of uiview

I have a UIView in a UITabController.
And there is a UITableView in it.
When toggling in call status bar it doesn't do anything and the view is not automatically resized.
It assumes the right size based on whether the in call UIStatusBar was toggled when the app starts but if the UIStatusBar is toggled whilst the app is running nothing changes.
Another tab view with a UINavigationController seems to resize fine.
Here is the code
if ([indexPath indexAtPosition:0] == 0 || [indexPath indexAtPosition:0] == 1) {
if (!airportChooser) {
airportChooser = [[AirportChooserController alloc] init];
airportChooser.targetController = self;
airportChooser.view.autoresizesSubviews = YES;
airportChooser.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[airportChooser.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
}
airportChooser.target = [indexPath indexAtPosition:0];
[self.parentViewController.parentViewController.view addSubview:airportChooser.view];
self.parentViewController.parentViewController.view.autoresizesSubviews = YES;
self.parentViewController.parentViewController.view.contentMode = UIViewContentModeRedraw;
[self.parentViewController.parentViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
airportChooser.view.contentMode = UIViewContentModeRedraw;
//[airportChooser open];
}
Did you set the resizing mask of the UIView correctly? You can set it in Interface Builder in the size tab, it's the red lines that you can click.
You can also set it in code using something like:
[view setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight];
Also make sure the superview has set autoresizesSubviews to YES.
You can find more information about this in the UIView documentation.
Whilst klaaspeiter's answer makes sense and in some cases may be the right answer
in my specific case it was because I was adding a sub view to a UINavigationController's view with addSubview instead of pushViewController:view animated:NO;