Comments (11)
Yes, you can use it in any UIView
, just put your layout code in layoutSubviews
.
from facade.
Thank you! Will try it!
from facade.
No problem, LMK if you have issues!
from facade.
Maybe I'm doing something wrong when reusing the cells, but I don't think so. Look at the behavior of the cells.
Look at this video -> https://www.dropbox.com/s/uc9jqdpmvofom4v/Untitled.mov?dl=0
Let me know,
Thanks
#import "TableViewController.h"
#import "Cell.h"
#import "UIView+Facade.h"
@interface TableViewController ()
{
UILabel *_label;;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self layoutFacade];
}
- (void)layoutFacade {
[_label anchorTopRightWithRightPadding:10 topPadding:10 width:110 height:20];
}
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath;
{
return 200;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cell";
Cell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.userInteractionEnabled = YES;
_label = [UILabel new];
[_label sizeToFit];
_label.font = [UIFont systemFontOfSize:24];
_label.text = @"Pruebaaa";
[cell addSubview:_label];
// Configure the cell...
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.backgroundColor = [UIColor colorWithRed:0.957 green:0.957 blue:0.957 alpha:1] /*#f4f4f4*/;
return cell;
}
from facade.
I'm reading this on a phone at the moment so not 100% sure, but it looks like your adding 1 instance of a label as a subview to multiple cells.
from facade.
Correct, and it won't show that label until I scroll the view. Which is weird.
If I do cell.textlabel.text it will show at the beginning with no scrolling needed.
from facade.
Yeah the problem has nothing to do with Facade or the layout, it has to do with cell reuse. You cant have the same view as a subview of multiple views. Each cell needs its own instance of that label.
from facade.
I understand, what would be the best practice here to use Facade on a UITableViewCell?
from facade.
Subclass UITableViewCell, put a label in there, and in that cell's layoutSubviews method is where you would have your Facade code.
from facade.
In one of my open source apps, I have a UICollectionViewCell I do this with. You can reference the source here:
https://github.com/mamaral/xkcd-Open-Source/blob/master/Source/Views/Comic%20Cell/ComicCell.m
from facade.
I will check it out!
Thank you man!
Sent from my iPhone
On Sep 27, 2015, at 1:36 PM, Mike Amaral [email protected] wrote:
In one of my open source apps, I have a UICollectionViewCell I do this with. You can reference the source here:
https://github.com/mamaral/xkcd-Open-Source/blob/master/Source/Views/Comic%20Cell/ComicCell.m
—
Reply to this email directly or view it on GitHub.
from facade.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facade.