Giter Site home page Giter Site logo

Using it in UITableViewCell about facade HOT 11 CLOSED

mamaral avatar mamaral commented on June 23, 2024
Using it in UITableViewCell

from facade.

Comments (11)

mamaral avatar mamaral commented on June 23, 2024

Yes, you can use it in any UIView, just put your layout code in layoutSubviews.

from facade.

danglade avatar danglade commented on June 23, 2024

Thank you! Will try it!

from facade.

mamaral avatar mamaral commented on June 23, 2024

No problem, LMK if you have issues!

from facade.

danglade avatar danglade commented on June 23, 2024

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.

mamaral avatar mamaral commented on June 23, 2024

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.

danglade avatar danglade commented on June 23, 2024

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.

mamaral avatar mamaral commented on June 23, 2024

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.

danglade avatar danglade commented on June 23, 2024

I understand, what would be the best practice here to use Facade on a UITableViewCell?

from facade.

mamaral avatar mamaral commented on June 23, 2024

Subclass UITableViewCell, put a label in there, and in that cell's layoutSubviews method is where you would have your Facade code.

from facade.

mamaral avatar mamaral commented on June 23, 2024

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.

danglade avatar danglade commented on June 23, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.