• 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
Re: initWithCoder but I do not have nib file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initWithCoder but I do not have nib file


  • Subject: Re: initWithCoder but I do not have nib file
  • From: Agha Khan <email@hidden>
  • Date: Sat, 15 Aug 2009 12:00:35 -0700

Thank for reply.

First of all I should had written
self.helpButton = [UIButton buttonWithType:UIButtonTypeCustom];
Not UIButtonTypeRoundedRect

CustomButton*myButton = [CustomButton buttonWithType: UIButtonTypeCustom];


That does not work either, even my base class is UIButton for CustomButton.
This is a new bug and it should had init through CustomButton, but it didn't. This code just returns me UIButton*.
After that there is no point because It has not gone through my code and unable apply any custom attributes.


Work around  and it works.
call [self Attach:myButton];

- (void) Attach:(UIButton*) btn
{
[btn.titleLabel setNumberOfLines:0];
[btn.titleLabel setLineBreakMode:UILineBreakModeWordWrap];

btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
if (!normalImage)
{
UIImage *image = [UIImage imageNamed:@"customButtonImageDefault.png"];
normalImage =[image stretchableImageWithLeftCapWidth:12 topCapHeight: 12];
}

if (!pressedImage)
{
UIImage *image = [UIImage imageNamed:@"customButtonImageDown.png"];
pressedImage = [image stretchableImageWithLeftCapWidth:12 topCapHeight:12];
}

[btn setBackgroundImage:normalImage forState:UIControlStateNormal];
[btn setBackgroundImage:pressedImage forState:UIControlStateHighlighted];

[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

}







On Aug 15, 2009, at 8:08 AM, Luke the Hiesterman wrote:

For some reason I don't have this original email in my inbox, but to the author:

As you've observed, initWithCoder: is called when your object is instantiated from a nib. Since you don't have a nib, and you're instantiating the object in code, you should not use initWithCoder:. Instead you should use the designated initializer of the given class. The blog entry doesn't include the full interface of the class, so I don't know exactly what the designated initializer is, but given that it's a UIButton subclass, and UIButtons are instantiated from a class method, I would expect that it needs to be instantiated from a class method also, like this:

CustomButton*myButton = [CustomButton buttonWithType:UIButtonTypeRoundedRect];

Luke


On Aug 15, 2009, at 5:07 AM, Agha Khan wrote:

Hi:
I was looking a blog about customButton


http://supergravelynbros.com/?p=871


The author explained that initializing with - (id)initWithCoder:(NSCoder *)coder

I implemented something like this
self.helpButton = [CustomButton initWithCoder:UIButtonTypeRoundedRect];
which complies OK, but get exception at this point.


I know the reason I do not have a nib file, but I believe I don't need it.

According to author
The initWithCoder: method is what will be called when the game reads the button in from the nib files.


But I do not have any nib file in my project. What can we do in such situation?


_______________________________________________

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

_______________________________________________

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: initWithCoder but I do not have nib file
      • From: Scott Ribe <email@hidden>
References: 
 >initWithCoder but I do not have nib file (From: Agha Khan <email@hidden>)
 >Re: initWithCoder but I do not have nib file (From: Chase Meadors <email@hidden>)
 >Re: initWithCoder but I do not have nib file (From: Luke the Hiesterman <email@hidden>)

  • Prev by Date: Re: Aqua animations drawing from separate thread
  • Next by Date: observeValueForKeyPath returns null in the change directory???
  • Previous by thread: Re: initWithCoder but I do not have nib file
  • Next by thread: Re: initWithCoder but I do not have nib file
  • Index(es):
    • Date
    • Thread