• 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: iOS: UITableViewCell an textlabel?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS: UITableViewCell an textlabel?


  • Subject: Re: iOS: UITableViewCell an textlabel?
  • From: sebi <email@hidden>
  • Date: Wed, 4 Aug 2010 10:30:56 +0200

hello,

thanks for your reply. I planned it to do like you suggested, but it seems to work with the built-in label when I make sure to call super in layoutSubviews.
would you still recommend to use my own label?

thanks and regards,
sebastian mecklenburg

On 04.08.2010, at 03:40, Bill Garrison wrote:

> Sebastian,
>
> If you doing a UITableViewCell subclass, you'll have issues using the built-in textLabel property if you want it to be positioned somewhere other than the locations provided by the built-in styles.
>
> Your best bet is to add your own UILabel to the subclass' contentView.
>
> @interface MyTableViewCell : UITableViewCell {
> 	UILabel *myOwnTextLabel;
> }
> @property (nonatomic, retain) UILabel *myOwnTextLabel;
> @end
>
> @implementation MyTableViewCell
> - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier {
> 	self = [super initWithStyle:style reuseIdentifier: reuseIdentifier];
> 	if (self) {
> 		CGRect r = self.contentView.bounds;
> 		r.origin.x = 30;
> 		r.origin.y = 5;
> 		r.size.width -= 50;
> 		r.size.height -= 10;
> 		myOwnTextLabel = [[UILabel alloc] initWithFrame:r];
>
> 		[self.contentView addSubview: myOwnTextLabel];
> 		// Add your own UILabel to the content view
> 		// You'll ignore the built-in textLabel property and use your own, myOwnTextLabel.
> 	}
> 	return self;
> }
>
> - (void) dealloc {
> 	[myOwnTextLabel release]; myOwnTextLabel = nil;
> 	[super dealloc];
> }
>
> - (void) setText: (NSString *)text {
> 	myOwnTextLabel.text = text;
> }
> @end
>
> On Aug 3, 2010, at 1:24 PM, sebi wrote:
>
>> Hello,
>>
>> In my project (iPad) I use a UITableViewCell subclass. The problem is, that the built in textLabel doesn't show the text.
>> Here is some test code:
>>
>> -(void)setText:(NSString*)text {
>> 	CGRect r;
>> 	r.origin.x = 30;
>> 	r.origin.y = 5;
>> 	r.size.width = self.bounds.size.width - 50;
>> 	r.size.height = self.bounds.size.height - 10;
>> //	self.textLabel.frame = r;
>> //	self.textLabel.text = @"xxx";
>> 	UILabel* textLabel = [[UILabel alloc] initWithFrame:r];
>> 	textLabel.text = @"xxx";
>> 	[self addSubview:textLabel];
>> 	[textLabel release];
>> }
>>
>> when I uncomment the two lines and comment out the last three lines it doesn't work, no text visible. The _textLabel member of the UITableViewCell superclass is not nil and its parameters are set correctly.
>> I mean, it works now (I have to make my textLabel a member and add it only once as a subview of course) but I would still be interested what I am doing wrong.
>>
>> Thanks and regards,
>> Sebastian Mecklenburg_______________________________________________
>
>

_______________________________________________

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: iOS: UITableViewCell an textlabel?
      • From: Steve Christensen <email@hidden>
References: 
 >iOS: UITableViewCell an textlabel? (From: sebi <email@hidden>)
 >Re: iOS: UITableViewCell an textlabel? (From: Bill Garrison <email@hidden>)

  • Prev by Date: Re: iOS: UITableViewCell an textlabel?
  • Next by Date: UIImageView and UIViewContentModeBottomLeft
  • Previous by thread: Re: iOS: UITableViewCell an textlabel?
  • Next by thread: Re: iOS: UITableViewCell an textlabel?
  • Index(es):
    • Date
    • Thread