• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Custom View drawRect method is not invoked when use with AutoLayout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom View drawRect method is not invoked when use with AutoLayout


  • Subject: Custom View drawRect method is not invoked when use with AutoLayout
  • From: Sasikumar JP <email@hidden>
  • Date: Wed, 16 Jan 2013 21:47:52 +0530

Hi,
  I am working on a project, where i have to create horizontal tableview
with custom tableview cell. i am using AutoLayout constraints to layout all
cell's subview elements.

Here is the my tableview cell init method, here i am using JPFilmBorderView
to draw some custom drawing. but JPFilmBorderView drawRect method never
gets invoked.

- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier

{

    NSLog(@"initwithstyle invoked");

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        JPFilmBorderView *topFilmBorderView = [[JPFilmBorderView alloc]
initWithFrame:CGRectZero];

        topFilmBorderView.contentMode = UIViewContentModeRedraw;

        topFilmBorderView.backgroundColor = [UIColor whiteColor];

        topFilmBorderView.translatesAutoresizingMaskIntoConstraints = NO;



        JPFilmBorderView *bottomFilmBorderView = [[JPFilmBorderView alloc]
initWithFrame:CGRectZero];

        bottomFilmBorderView.translatesAutoresizingMaskIntoConstraints = NO;

        bottomFilmBorderView.backgroundColor = [UIColor greenColor];



        self.thumbnailImage = [[UIImageView alloc] initWithFrame:CGRectZero
];

        _thumbnailImage.translatesAutoresizingMaskIntoConstraints = NO;


        [self.contentView addSubview:topFilmBorderView];

        [self.contentView addSubview:_thumbnailImage];

        [self.contentView addSubview:bottomFilmBorderView];



        NSDictionary *viewDict = NSDictionaryOfVariableBindings(
_thumbnailImage, topFilmBorderView, bottomFilmBorderView);

        [self.contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:
@"V:|[topFilmBorderView(20)]-[_thumbnailImage]-[bottomFilmBorderView(20)]|"
options:0 metrics:nil views:viewDict]];

        [self.contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[topFilmBorderView]" options:0 metrics:nil
views:viewDict]];

        [self.contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[_thumbnailImage]" options:0 metrics:nil
views:viewDict]];

        [self.contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[bottomFilmBorderView]" options:0 metrics:
nil views:viewDict]];



    }

    return self;

}

Here is the JPFilmBorderView implementation.i never see the NSLog output
from drawRect method.

============================

@implementation JPFilmBorderView

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

    }

    return self;

}

- (void)drawRect:(CGRect)rect

{

    NSLog(@"Rect %@",[NSValue valueWithCGRect:rect]);

}

I am observing this problem only if i define the custom view from program,
where as if i use storyboard/nib file, custom view drawRect method is
getting invoked.

i am not sure what i am missing here. any help is highly appreciated.

Thank you

Sasikumar JP
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Custom View drawRect method is not invoked when use with AutoLayout
      • From: Sasikumar JP <email@hidden>
    • Provisioning profiles
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: NSString and file system Re: AppleScript in Sandboxed App
  • Next by Date: Provisioning profiles
  • Previous by thread: Re: How do I implement the container view which represent the thumbnail of video having variable cell sizes?
  • Next by thread: Provisioning profiles
  • Index(es):
    • Date
    • Thread