So my rootViewController contains a UICollectionView with a Custom UICollectionViewCell. I have a label on the cell for a header which shouldn’t ever change and I have a multi-line Label making up the body of the rest of the cell. When I launch the app it calls the sizeToFit correctly and top aligns everything so it isn’t centered. I click on one of the cells and go to the next view, then if I click the back button to go back to the rootViewController it does run the viewWillAppear method and reloads the data but the sizeToFit does not work and everything on the multi-line label becomes center aligned. It is still multiple lines but if there is only a couple of lines it sits in the center of the label and it doesn’t look good. How can I keep this so it is consistant. I have a left menu that will reload the rootViewController which will position the label correctly again but once I hit the back button from the secondViewController it is no longer aligned. Is there a way to make it clear all of the cells and reload them. I have tried the [collectionView reloadData]; in the viewWillAppear and it doesn’t work, it is currently called at the end of the connectionDidFinish which the network connection is called from the viewWillAppear method. Any assistance is appreciated.
This is the custom UICollectionViewCell code
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
[contentLabel setNumberOfLines:0];
[contentLabel sizeToFit];
}
RootViewController
-(UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:
(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"LocationListCell";
LocationList *cell = [cv dequeueReusableCellWithReuseIdentifier:cellIdentifier
forIndexPath:indexPath];
[cell.titleBar setText:[value objectAtIndex:indexPath.row]];
NSArray *tempObject = [[NSArray alloc] initWithArray:[self getData:[key
objectAtIndex:indexPath.row]]];
NSMutableString *tempString = [[NSMutableString alloc] init];
for (int i = 0; i < [tempObject count]; i++)
{
[tempString appendString:[tempObject objectAtIndex:i]];
[tempString appendString:@"\r"];
}
//[cell.contentLabel sizeToFit];
//[cell.contentLabel setNumberOfLines:0];
[cell.contentLabel setText:tempString];
return cell;
}
Use this dynamic
UILablewith this custom method…just add this bellow method in your
.mfileand use it like bellow..
hope this help you…