Centering a UILabel in a UITableViewCell

I have a simple application that uses a few non-standard UITableViewCellStyles (like UITableViewCellStyleValue1, UITableViewCellStyleValue2).
When I run the app in the Simulator the labels (whether I assign text to textLabel or detailTextLabel or both) are centered vertically. Unfortunately, when I run the app on the (first generation iTouch 32GB) device, the UILabel's don't necessarily vertically line up in the middle of the cell. I've done some additional debugging and determined that when I use UITableViewCellStyleValue1 or UITableViewCellStyleValue2 - it seems that if I assign text to just one or the other labels, "cell.textLabel.text" or "cell.detailTextLabel.text" - then said kabel will appear 'higher' than the middle of the cell.
If I assign text to both labels then both of the labels are vertically centered.
I am running the most recent version of Xcode (3.1.4) and deploying to an iTouch running iPhoneOS 3.1.2 SDK. As I mentioned, it is a a first generation iTouch 32GB unit.
Any idea what is happening?

That is a good question.
I'm not setting anything explicitly. I'm simply assigning text to those labels and letting the cell's named style render itself. Maybe I'll strip the controller down and make sure I'm not indirectly affecting the layout or drawing methods.
The text appears to draw correctly (not bitmapped) but what confounds me is that the labels vertically center themselves when I assign values to both of them (textLabel and detailTextLabel).
The iTouch device is a first gen device running 3.1.2.

Similar Messages

  • Unrecognized selector sent to instance  ** plz help

    I have a navigation controlled app that display's different table views as you navigate down the path. I decided that I wanted to show a CustomCell instead of the regular default cells provided for the grouped style table.
    I created the CustomCell.h and CustomCell.m files along with the CustomCell.xib nib file.
    I have done this MANY times before in other projects but this one will not let me set any of the fields on the CustomCell. I have stipped this cell down to just one data element called 'desc' and it is a UILabel I am trying to set.
    Here is the CustomCell.h file and some of the .m file using the CustomCell class.
    #import <UIKit/UIKit.h>
    @interface CustomCell : UITableViewCell {
    IBOutlet UILabel *desc;
    @property (nonatomic, retain) IBOutlet UILabel *desc;
    @end
    - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
    CustomCell *cell2 = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
    if (cell2 == nil)
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell2 = [nib objectAtIndex:0];
    ...do some logic
    cell2.desc.text = [NSString stringWithFormat:@"%@", myText]; //ERROR OCCURS HERE
    return cell2;
    I receive the following error:
    4/4/09 2:27:20 PM todo[1484] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSObject desc]: unrecognized selector sent to instance 0x5239b0'
    The links are all set in IB and the CustomCell is set to be of Class "CustomCell"
    Anyone have any idea why I cannot set the value of the UILabel for the cell2 object?
    Thanks in advance

    RayNewbie wrote:
    I think the recommendation was to make sure the object you got from your nib was an instance of the class you expected. This sounds like an especially good idea given the difference in behavior on the two platforms. For example:
    if (cell2 == nil)
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell2 = [nib objectAtIndex:0];
    // debug code aka introspection
    if ([cell2 isMemberOfClass:[CustomCell class]])
    NSLog(@"%@ is CustomCell", cell2);
    else {
    NSLog (@"%@ is not CustomCell", cell2);
    That is fairly limiting and isn't good practice. You see that approach more in C++, which isn't as strong an object-oriented language as Objective-C. Even in C++ though, there are better ways to handle it.
    In Objective-C, it is pretty easy. Look at it from the perspective of what you want to do. Then, you ask the object if it can do what you want via "respondsToSelector:"

  • IPhone: Vertically centering UILabel text

    The UILabel permits horizontal centering of its text via the textAlignment property, but there seems to be no way to align the text vertically. I have 3 labels, the last holding from one line to several. It if only has a single line, the text is vertically centered giving a big gap from he previous text. That looks uncool. (and in the Mac world, cool is everything). Is there some secret magical way to get UILabel to vertically center is text as well, or do I need to abandon labels and just drop down to drawRect.

    Check out NSString(UIStringDrawing). It has the following method, which you can use to calculate the size of the text as it would be in the label. Then you can set the label height to the minimum necessary for the text, which will solve your vertically centering problem.
    sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

  • Customizing UITableViewCell (image, label, button).

    I have an image and 4 UILabels in my tableViewCell. I need the image to be selectable and two labels to be selectable. I searched in documentation and I found nothing about writing selector for UILabel. So, I am trying to use UIButtons ( UIButtonTypeCustom) instead of the two UILabels. But, when I touch the cell the entire cell is selectable. How can I differentiate the labels, image and buttons in my UITableViewCell.
    I need the image to be selectable. I wanted to add a video in place of the image.
    How can I make all this possible.
    Thank You.

    http://www.iphonesdkarticles.com/2008/08/table-view-tutorial-tableview-cell.html
    http://iphoneincubator.com/blog/windows-views/display-rich-text-using-a-uiwebvie w
    Google is your friend...

  • How to manage the uitableviewcell after being scrolled?

    Hi all.
    I manipulated the cell of the table view to be a custom one, which will be expanded(from height=50 to height=100) on selection and will be srinked to original(from height=100 to height=50) on second click or deselction. Now my problem is that i am selecting a row and without deselecting it or without clicking it for second time if i am scrolling the table ,the cell should reload to the original(height=50) srinked one. Here the view is reloading but the height for that row is not srinking(still height for that row remains to be 100). Can anyone have tried like this? Plz help me to sort out the problem.
    Tanks in advance.
    Satya.

    Well sorry for late responsse, here is the code:_
    @interface HomeControl : UIViewController<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource >
              IBOutlet UITableView *newsTable;
              NSArray *dataArray;
              NSMutableArray *selectedRowArray,*clickedCountArray;
              CGRect frame;
    @property (nonatomic,retain) UITableView *newsTable;
    @property (nonatomic,retain) NSArray *dataArray;
    @property (nonatomic,retain) NSMutableArray *selectedRowArray,*clickedCountArray;
    @end
    @implementation HomeControl
    @synthesize newsTable,dataArray,selectedRowArray,clickedCountArray;
    - (void)viewDidLoad
              //table view section
                        NSDictionary *row1=[[NSDictionary alloc] initWithObjectsAndKeys:@"News",@"newsCatagory",@"News Title",@"newsTitle",nil],*row2=[[NSDictionary alloc] initWithObjectsAndKeys:@"News'it",@"newsCatagory",@"News Title",@"newsTitle",nil],*row3=[[NSDictionary alloc] initWithObjectsAndKeys:@"News",@"newsCatagory",@"News Title",@"newsTitle",nil],*row4=[[NSDictionary alloc] initWithObjectsAndKeys:@"Fashion",@"newsCatagory",@"Good Deal Title",@"newsTitle",nil],*row5=[[NSDictionary alloc] initWithObjectsAndKeys:@"News",@"newsCatagory",@"News Title",@"newsTitle",nil];
                        NSArray *a=[[NSArray alloc] initWithObjects:row1,row2,row3,row4,row5,nil];
                        self.dataArray=a;
                        [row1 release];[row2 release];[row3 release];[row4 release];[row5 release];[a release];
                        selectedRowArray=[[NSMutableArray alloc] initWithCapacity:dataArray.count];
                        clickedCountArray=[[NSMutableArray alloc] initWithCapacity:dataArray.count];
                        for(int i=0; i<[dataArray count]; i++)
                                  [selectedRowArray addObject:[NSNumber numberWithInt:0]];
                                  [clickedCountArray addObject:[NSNumber numberWithInt:0]];
    - (void)viewDidUnload
              // Release any retained subviews of the main view.
              // e.g. self.myOutlet = nil;
              self.newsTable=nil; self.selectedRowArray=nil;          self.clickedCountArray=nil;
              self.dataArray=nil;
              [super viewDidUnload];
    - (void)dealloc
              [newsTable release]; [selectedRowArray release]; [clickedCountArray release];
              [dataArray release];
        [super dealloc];
    #pragma mark Custom Methods
    -(void)cellWithDataInTableForCell:(TableDataCellControl*)tCell withIndexPath:(NSIndexPath*)ip
              NSUInteger r=[ip row];
              NSDictionary *rowdata=[self.dataArray objectAtIndex:r];
              tCell.newsL.text=[rowdata objectForKey:@"newsCatagory"];
              tCell.title.text=[rowdata objectForKey:@"newsTitle"];
              if(tCell.newsL.text==@"Fashion")
                        tCell.rowImage.image=[UIImage imageNamed:@"orange.png"];
              else if(tCell.newsL.text==@"News'it")
                        tCell.rowImage.image=[UIImage imageNamed:@"IT-Icon.png"];
                        tCell.rowImage.backgroundColor=[UIColor clearColor];
              else
                        tCell.rowImage.image=nil;
              NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
              [formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
              tCell.timeL.text=[formatter stringFromDate:[NSDate date]];
              [formatter release];
    -(void)accessViewForCell:(TableDataCellControl*)tCell
              UILabel *l=[[UILabel alloc] initWithFrame:CGRectMake(0,0,10,12)];
              l.textAlignment=UITextAlignmentCenter;
              l.backgroundColor=[UIColor clearColor];
              l.textColor=[UIColor blueColor];
              if(tCell.selectedRow==0) l.text=@">";
              else l.text=@"<";
              tCell.accessoryView=l;
              tCell.accessoryView.userInteractionEnabled=YES;
              [l release];
    #pragma mark Table DataSource Methods
    -(NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)s
              return [self.dataArray count];
    -(NSString *)tableView:(UITableView *)tv titleForHeaderInSection:(NSInteger)s
              if(s==0)
                        return [NSString stringWithString:@"Actuallite"];
              else
                        return nil;
    -(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)ip
              static NSString *cid=@"CID";
              TableDataCellControl *tCell=(TableDataCellControl *)[tv dequeueReusableCellWithIdentifier:cid];
              if([[clickedCountArray objectAtIndex:ip.row] intValue]%2==0)
                        if(tCell==nil)
                                  NSArray *cellNib=[[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
                                  for(id ob in cellNib)
                                            if([ob isKindOfClass:[TableDataCellControl class]])
                                                      tCell=(TableDataCellControl *)ob;
                        tCell.selectedRow=[[selectedRowArray objectAtIndex:ip.row] intValue];
                        tCell.rowClicked=[[clickedCountArray objectAtIndex:ip.row] intValue];
                        [self cellWithDataInTableForCell:tCell withIndexPath:ip];
                        [self accessViewForCell:tCell];
              else
                        if(tCell==nil)
                                  NSArray *cellNib=[[NSBundle mainBundle] loadNibNamed:@"TableCellExtended" owner:self options:nil];
                                  for(id ob in cellNib)
                                            if([ob isKindOfClass:[TableDataCellControl class]])
                                                      tCell=(TableDataCellControl *)ob;
                        tCell.selectedRow=[[selectedRowArray objectAtIndex:ip.row] intValue];
                        tCell.rowClicked=[[clickedCountArray objectAtIndex:ip.row] intValue];
                        [self cellWithDataInTableForCell:tCell withIndexPath:ip];
                        [self accessViewForCell:tCell];
              return tCell;
    -(void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip
              TableDataCellControl *tCell=(TableDataCellControl *)[tv cellForRowAtIndexPath:ip],*newCell;
              tCell.rowClicked+=1;
              [clickedCountArray replaceObjectAtIndex:ip.row withObject:[NSNumber numberWithInt:tCell.rowClicked]];
              if(tCell.selectedRow==0)
                        tCell.selectedRow=1;
                        [selectedRowArray replaceObjectAtIndex:ip.row withObject:[NSNumber numberWithInt:tCell.selectedRow]];
              else
                        tCell.selectedRow=0;
                        [selectedRowArray replaceObjectAtIndex:ip.row withObject:[NSNumber numberWithInt:tCell.selectedRow]];
              [tv reloadRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationFade];
              tCell=(TableDataCellControl*)[tv cellForRowAtIndexPath:ip];
              if(tCell!=nil)
                        for(id ob in tCell.contentView.subviews)
                                  [ob removeFromSuperview];
              NSArray *cellNib=[[NSBundle mainBundle] loadNibNamed:@"TableCellExtended" owner:self options:nil];
              for(id ob in cellNib)
                        if([ob isKindOfClass:[TableDataCellControl class]])
                                  newCell=(TableDataCellControl *)ob;
              [self cellWithDataInTableForCell:newCell withIndexPath:ip];
              //[self accessViewForCell:tCell];
              [tCell.contentView addSubview:newCell.contentView];
              if((tCell.selectedRow==0)&&(tCell.rowClicked%2==0))
                        [self tableView:tv didDeselectRowAtIndexPath:ip];
    -(void)tableView:(UITableView *)tv didDeselectRowAtIndexPath:(NSIndexPath *)ip
              [clickedCountArray replaceObjectAtIndex:ip.row withObject:[NSNumber numberWithInt:0]];
              [selectedRowArray replaceObjectAtIndex:ip.row withObject:[NSNumber numberWithInt:0]];
              int c,s;
              c=[[clickedCountArray objectAtIndex:ip.row] intValue];s=[[selectedRowArray objectAtIndex:ip.row] intValue];
              [tv reloadRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationFade];
              TableDataCellControl *tCell=(TableDataCellControl *)[tv cellForRowAtIndexPath:ip],*newCell;
              if(tCell!=nil)
                        for(id ob in tCell.contentView.subviews)
                                  [ob removeFromSuperview];
              NSArray *cellNib=[[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
              for(id ob in cellNib)
                        if([ob isKindOfClass:[TableDataCellControl class]])
                                  newCell=(TableDataCellControl *)ob;
              [self cellWithDataInTableForCell:newCell withIndexPath:ip];
              //[self accessViewForCell:tCell];
              [tCell.contentView addSubview:newCell.contentView];
    -(CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)ip
              int cliked=[[clickedCountArray objectAtIndex:ip.row] intValue],selection=[[selectedRowArray objectAtIndex:ip.row] intValue];
              int check=(cliked%2==0)&&(selection==0)?0:1;
              switch (check)
                        case 0:
                                  return 49;
                                  break;
                        case 1:
                                  return 100;
                                  break;
                        default:
                                  return 49;
                                  break;
    @end

  • How can we find whether we clicked UIImage or text in UItableViewCell

    In tableview didselectrowatindexpath method how can we find if we click image in that cell[i mean the image which i set using cell.image ] or text in that cell[i mean the text which i set using cell.textlabel.text]
    Basically i have to do separate functionality if i click image or text....
    I have customized the cell and put view for this thing but bluecolor selection is not coming while i click that cell....
    Please help me out.....

    //////////// Custom tableviewcell....
    - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier tableView:(UITableView*)tableview cellRow:(NSInteger)cellRow cellSection:(NSInteger)cellSection{
    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
    // Initialization code
    ratingView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,30, 35)];
    textLabel=[[UILabel alloc] initWithFrame:CGRectMake(37,0, self.frame.size.width, self.frame.size.height-9)];
    //[textLabel setBackgroundColor:[UIColor redColor]];
    textLabel.textAlignment=UITextAlignmentLeft;
    //textLabel.text=@"sample";
    [textLabel setFont:[UIFont boldSystemFontOfSize:18]];
    [ratingView setImage:[UIImage imageNamed:@"Rating.png"]];
    [self addSubview:textLabel];
    [self addSubview:ratingView];
    [textLabel setTextColor:[UIColor blackColor]];
    [textLabel setHighlightedTextColor:[UIColor whiteColor]];
    imageChanged=NO;
    chaptersTableView=tableview;
    row=cellRow;
    section=cellSection;
    return self;
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    NSLog(@"I m inside touches began method");
    for ( UITouch *touch in touches )
    CGPoint touchPoint = [touch locationInView:self];
    CGRect imageRect = CGRectMake(0, 0, 40, self.frame.size.height);
    if ( CGRectContainsPoint(imageRect, touchPoint) )
    NSLog(@"I have clicked on imageview");
    else
    //[self setBackgroundColor:[UIColor colorWithRed:2.0/255.0 green:114.0/255.0 blue:237.0/255.0 alpha:1.0]];
    //[self.textLabel setBackgroundColor:[UIColor colorWithRed:2.0/255.0 green:114.0/255.0 blue:237.0/255.0 alpha:1.0]];
    NSLog(@"I have clicked on tableView");
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    //NSLog(@"I am inside touches cancelled");
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    @try
    for ( UITouch *touch in touches )
    CGPoint touchPoint = [touch locationInView:self];
    CGRect imageRect = CGRectMake(0, 0, 40, self.frame.size.height);
    if ( CGRectContainsPoint(imageRect, touchPoint) )
    // NSLog(@"I have clicked on imageview");
    if(!imageChanged)
    //[_imageViewTarget performSelector:changeImageAction];
    [self.ratingView setImage:[UIImage imageNamed:@"Rating-filled.png"]];
    [self setImageChanged:YES];
    else
    [self.ratingView setImage:[UIImage imageNamed:@"Rating.png"]];
    [self setImageChanged:NO];
    else
    NSIndexPath *newSetRow = [NSIndexPath indexPathForRow:row inSection:section];
    [chaptersTableView selectRowAtIndexPath:newSetRow animated:NO scrollPosition:UITableViewScrollPositionNone];
    //[chaptersTableView selectRowAtIndexPath:<#(NSIndexPath *)indexPath#> animated:<#(BOOL)animated#> scrollPosition:<#(UITableViewScrollPosition)scrollPosition#>
    [_imageViewTarget performSelector:changeImageAction];
    //NSLog(@"I have clicked on tableView");
    //NSLog(@"I m inside touches ended ");
    @catch (NSException *ex) {
    NSLog(@"Exception caught %@",[ex description]);
    -(void)setImageViewTarget:(id)target action:(SEL)action
    _imageViewTarget=target;
    changeImageAction=action;
    -(void)checkImage
    if(self.imageChanged)
    NSLog(@"imchan %@",self);
    //NSLog(@"I m going to change the filled image");
    [self.imageView setImage:[UIImage imageNamed:@"Rating-filled.png"]];
    else
    NSLog(@"imnotch %@",self);
    ////////////// my view controller
    - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
    cell=(CustomTableCell*)[tv dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Identifier for row %d in section %d",indexPath.row,indexPath.section]];
    if(cell==nil)
    //cell=[[[CustomTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Identifier for row %d in section %d",indexPath.row,indexPath.section] tableView:tv] autorelease];
    cell=[[[CustomTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Identifier for row %d in section %d",indexPath.row,indexPath.section] tableView:tv cellRow:indexPath.row cellSection:indexPath.section]autorelease];
    //cell=[[[CustomTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Identifier for row %d in section %d",indexPath.row,indexPath.section]] autorelease];
    NSLog(@"** %d sec %d ** %@",[indexPath row],[indexPath section],cell);
    [cell setImageViewTarget:self action:@selector(changeImageView)];
    NSLog(@"%d***",cell.frame.size.height);
    @try {
    if(searchResults)
    [cell.textLabel setText:[searchResultArray objectAtIndex:indexPath.row]];
    else
    switch (indexPath.section) {
    case 0:
    [cell.textLabel setText:[[nameDictionary objectForKey:@"a"] objectAtIndex:indexPath.row]];
    break;
    case 1:
    [cell.textLabel setText:[[nameDictionary objectForKey:@"b"] objectAtIndex:indexPath.row]];
    break;
    case 2:
    [cell.textLabel setText:[[nameDictionary objectForKey:@"c"] objectAtIndex:indexPath.row]];
    break;
    default:
    break;
    @catch (NSException *ex ){
    NSLog(@"Exception caught %@",[ex description]);
    //if(indexPath.row<10)
    // [cell.textLabel setText:[NSString stringWithFormat:@"sample %d in section %d",indexPath.row,indexPath.section]];
    [cell checkImage];
    [cell setImageViewTarget:self action:@selector(changeImageView)];
    //cell.selectionStyle=UITableViewCellSelectionStyleBlue;
    return cell;
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    NSLog(@"I am inside did select row at index path");
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    //[tableView getHeaderView];
    if(searchResults)
    return 1;
    return 3;
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    if(searchResults)
    return [[[searchResultArray objectAtIndex:0] capitalizedString] substringToIndex:1];
    else
    if(section==0)
    //[tableView getHeaderView];
    return @"A";
    else if(section==1)
    //[tableView getHeaderView];
    return @"B";
    else if(section==2)
    //[tableView getHeaderView];
    return @"C";
    return @"";
    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
    return [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@" M",@"N",@"O",@"P",nil];
    -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    //NSLog(@"i m inside touches began method");
    -(void)changeImageView
    //NSIndexPath *newSetRow = [NSIndexPath indexPathForRow:2 inSection:0];
    //[mTableView selectRowAtIndexPath:newSetRow animated:NO scrollPosition:UITableViewScrollPositionNone];
    NSLog(@"I m inside changeImageView");
    SampleViewController *sample=[[SampleViewController alloc] init];
    [self.navigationController pushViewController:sample animated:NO];
    //[cell.ratingView setImage:[UIImage imageNamed:@"Rating-filled.png"]];
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    return 36;
    }

  • UITableViewCell initWithFrame:CGRectMake Autoresizing Problems..

    Hello...
    There are problems defining the Frame for my TableViewCell.. the documentation describes to approaches as mentioned (i've quoted them at the bottom), and I am implementing the first one - therfore, just adding views as subviews. It is looking like this - and is working more or less:
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    UILabel * nickLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, 50.0, 20.0)] autorelease];
    nickLabel.text = [tempDict valueForKey:@"id"];
    nickLabel.font = [UIFont systemFontOfSize:12.0];
    nickLabel.textAlignment = UITextAlignmentRight;
    nickLabel.textColor = [UIColor blueColor];
    nickLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleHeight;
    [cell.contentView addSubview:nickLabel];
    the problem is, that as I am adding more and more subviews, I need more space for doing so. But it seems that my cellView is not "autoresizing" even if i define it with a special Rect like
    cell = [[[UITableViewCell alloc] initWithFrame:CGRect(0.0, 0.0, 400.0, 100.0) reuseIdentifier:MyIdentifier] autorelease];
    sure, this approach is not documented (the doc says use RectZero..) but i am just trying.. for example this Rect setting of my label looks like as if it would be in the third tableView Row.
    UILabel * nickLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 100.0, 50.0, 20.0)] autorelease];
    any ideas?
    +■You should add subviews to a cell’s content view when your content layout can be specified+
    +entirely with the appropriate autoresizing settings and when you don’t need to modify the default+
    +behavior of the cell.+
    +■ You should create a custom subclass when your content requires custom layout code or when+
    +you need to change the default behavior of the cell, such as in response to editing mode.+

    http://iphone.zcentric.com/2008/08/05/custom-uitableviewcell/ helped.
    +change. How do I increase the size of each cell?+
    +# mikezupan Says:+
    +August 25th, 2008 at 8:39 am+
    @Turbolag
    +the only way I have found to edit the height of a cell is doing it in the tableView.+
    +-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {+
    +return 100.0; //returns floating point which will be used for a cell row height at specified row index+

  • How to edit label in custom UITableViewCell?

    Hi, I'm a newby in iPhone programming, I have created a custom UITableViewCell with 3 labels and I have populated an UITableView with some rows. I need to change the text of one of the labels when the user select the cell.
    I wrote this:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *theCellSelected = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    theCellSelected = [theTableView cellForRowAtIndexPath:indexPath.row];
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    ..but nothing happen to the label, the text doesn't change..
    What's wrong?
    Thank you!
    PS: sorry for my english, I'm italian and I don't speak it very well..

    Hi Zoodany, and welcome to the Dev Forum!
    zoodany wrote:
    I wrote this:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    theTableView = tableView;
    // remove --> static NSString *CellIdentifier = @"Cell";
    UITableViewCell *theCellSelected;
    // remove --> = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    theCellSelected = [theTableView cellForRowAtIndexPath:indexPath]; // <-- remove '.row'
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    Assuming your @interface, xib and DataSource methods are consistent with the above, the only thing stopping your code from working would be the 'indexPath.row' arg as commented. The lines which dequeue a cell won't prevent your code from running, though if any cells are actually in the queue, you'll have a memory leak there.
    However, I doubt the code you posted is the same as the code you tested. If you actually coded cellForRowAtIndexPath:indexPath.row, you should have gotten a warning since 'row' is an int instead of a pointer. And if you had ignored that warning the program would have crashed at that line. This kind of mixup often happens when the programmer keys code into the forum instead of pasting it directly from the source file. Please copy and paste when posting your code here (also see the alert about formatting code, the first topic of the forum), ok?
    If indeed 'indexPath.row' is a red herring, I think we need to look elsewhere in your project for the problem.
    I have created a custom UITableViewCell
    This contradicts your code somewhat. If you subclassed UITableViewCell, you'd normally add ivars with matching @properties to the custom cell so you could access the subviews as cell.label1, cell.label2, etc. Using viewWithTag to find one of the labels suggests that you simply added the labels to vanilla UITableViewCell objects rather that subclassing (adding the labels without subclassing is probably the best choice if no further customization is required).
    So please let us know whether or not you actually defined a subclass of UITableViewCell. Assuming you didn't, here's an example of how to add labels to your cells (only two labels are added below to simplify the example):
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:CellIdentifier] autorelease];
    // make label 1
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 3, 140, 38)];
    label.text = @"Label 1";
    label.backgroundColor = [UIColor lightGrayColor];
    label.font = [UIFont boldSystemFontOfSize:20];
    label.tag = 1;
    [cell.contentView addSubview:label];
    [label release];
    // make label 2
    label = [[UILabel alloc] initWithFrame:CGRectMake(160, 3, 140, 38)];
    label.text = @"Label 2";
    label.backgroundColor = [UIColor yellowColor];
    label.font = [UIFont boldSystemFontOfSize:20];
    label.tag = 2;
    [cell.contentView addSubview:label];
    [label release];
    // Set up the cell...
    return cell;
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *theCellSelected = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *theLabelToEdit = (UILabel *)[theCellSelected viewWithTag:1];
    theLabelToEdit.text = @"Some Text..";
    Note that 'tableView' is used in the delegate method instead of an instance variable such as 'theTableView'. The 'tableView' parameter will always be set to the address of the table view which is calling the delegate method, so there's no need to use an ivar in this case. In fact, 'theTableView' could also be the cause of your problem. For example if you made the table view in IB, you might have forgotten to connect the 'theTableView' outlet of the controller (or File's Owner) to the UITableView object. So you might also check that connection, though the code above doesn't depend on it.
    Hope that helps!
    - Ray

  • UITableViewCell draws its text white a white background

    Has anyone had the problem where UITableViewCell draws its text with a white background, like this:
    !http://homepage.mac.com/markkrenek/cellbackground.png!
    This is a standard UITableViewCell in which I have specified has a background view, like this:
    cell.backgroundView = [[[UIView alloc] initWithFrame:cell.bounds] autorelease];
    cell.backgroundView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
    That's what's drawing gray. But the text label drawn by UITableViewCell draws with a white background obscuring a portion of the background view.
    I've tried numerous things like setting the cell and its content view to use clearColor as their background. The issue, I believe, is that the UILabel that UITableViewCell uses needs to have its background color set to clearColor. But there's no way to access that through the UITableViewCell API.

    As I mentioned, when I used a built in template, like contemporary, it worked too.  The problem only happened with the IBA that I was given.  Perhaps the previous owner of the file had accidentally chosen Format/Advanced/Define Default Glossary Style when they had some white on white displayed and caused all the formatting for the glossary to be the same.  I was able to fix it using that menu path.
    I'm not sure what fixing it in the "source file" means.  I was trying to fix it in the IBA file.  Not sure where else I would have fixed it.

  • Custom UITableViewCell: Recognizing which cell to update

    Hello,
    I have created a custom UITableViewCell in IB with two UIButtons and one UILabel. What I would like to do is have each button perform an action on the UILabel - lets just say change the UILabel's text for now. I have the following set up and everything works.
    MyViewController.m/h
    _ Has UITableViewCell property and IBOutlet connected to MyCustomTableCell
    _ Has two IBAction methods to handle each UIButton pressed
    MyCustomTableCell
    _ File Owner set to MyViewController
    _ Has tags denoting each item
    _ UIButtons events are connected to the custom methods in MyViewController.m
    Just as a test, I have populated 3 rows in the table. When I hit either UIButton from any row, it only updates the last row's UILabel text. The method that handles the UIButton's event is something like:
    -(IBAction)buttonOnePressed:(id)sender
    UILabel *myLabel = (UILabel*) [customLoadedCell viewWithTag:1];
    myLabel.text = @"button one";
    How do I recognize which row the button's event came from so I can only update that label?

    sptrakesh wrote:
    The button that triggered the event will be the child of the appropriate cell.
    Took me awhile but I finally understood what you meant. So basically what I did inside the method to handle the touch up event was:
    UITableViewCell *mycell = (UITableViewCell *)[[sender superview] superview];
    UILabel *myLabel = (UILabel*) [mycell viewWithTag:4];
    myLabel = @"test";
    The first line allows to get a reference to the UITableViewCell I tapped. If I needed the row number I could reference it by doing this:
    NSIndexPath *ip = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
    ip.row will return the row number.
    self.tableView is the reference to the table view.

  • How to delete the one of cost centers in Splitting Structure(OKEW)?

    Dear All,
    I have a question about Splitting Structure as below? Could I get favor from you? Thanks a lot.
    How to delete the one of cost centers in Splitting Structure(OKEW)?
    Jocha

    Hi Chang
    Welcome to SDN! Its our pleasure to help you here
    Step 1: Select your Cost Center in OKEW which is assigned to the Splitting Str
    Eg: Cost Ctr 1001 is assigned to Splitting Str Z1... Tick the Check box against 1001 under Z1 Splitting Str
    Step 2: Do a Single Click on the text "Non Assigned Cost Centers"
    Step 3: Press Shift +F6 (Or Click on the Assign Button, next to the Pencil icon)
    Br, Ajay M

  • How to have one centeral management console for DB and Application server?

    Hi
    Thank you for reading my post
    I read in several places that ORACLE provide facilitis that help developers to have one centeral console to manage Application server / Database and what ever oracle products.
    I want to know that, when i have Oracle 10g r2 and Application server 10.1.3.1 installed, how i can use that centeral management console?
    is it some other application that i should install ?
    or it is just some more configuration?
    thanks

    What you are looking for is called Grid Control.
    You will need the Grid Control Agent installed on each server that has products from Oracle's technology stack installed (database, web server, app server, etc). You will also need install the Grid Control software and repository.
    You can download Grid Control from the following link:
    http://www.oracle.com/technology/software/products/oem/index.html

  • Text "centered" in the HTML view

    I'm a new to JavaHelp. Experimenting with RoboHelp. I find th whole thing interesting. But when using "hsviewer", all the text apears centered when the HTML files are nicely left-aligned. When generating e.g WinHelp from the same project, they appear correctly. Please Help.
    -karl roth

    Hi Karl,
    I replied via e-mail as well: The difference is because of the SPAN tags in the HTML file(s) and the text-align:justify; in the CSS file.
    Java handles HTML 3.2 with some additions up to now. See http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/text/html/CSS.html and http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/text/html/HTMLEditorKit.html
    for some additional explanation
    Ulrich

  • Text elements not centered anymore once project goes live

    Hi guys,
    I've discovered Edge Animate a few days ago and I really love that it looks and feels a lot like After Effects - you should exchange and implement some functions of EA to AE (i.e. the curves easing options) & vice versa though
    What I went through, until know
    First of all, I am a Worpdress user using a responsive theme and the Edge Suite plug in.
    I've created a typo animation using a custom licensed web font and it took me a while to get it to work properly - the web-kit generated by the myfonts.com kit builder didnt' work with EA, so I had to let fontsquirrel create one instead. Now, the SVG font file gets exported upon export, but the EOT, WOFF and TTF files don't - not sure if it's a bug, but it's an easy thing to copy the files via FTP to the "../uploads/edge_suite/project/..." folder in order to fix this.
    My Problem
    After uploading the animation to my server via the Edge Suite plug in, approx. 50% of the text elements are not in the right place anymore. The affected elements are all offset by a fixed amount of pixels vertically, while they actually should be centered. When I run the HTML file of the exported web animation locally, everything's fine though.
    The problem occurs in Chrome, Safari, Firefox and on the iPhone.
    Has anyone experienced a similar issue?
    Will

    It seems like it is related to Wordpress or the Edge Suite plug in.
    HTML
    I've uploaded the animation (using web publishing) to a folder on my server, and everything is fine.
    Wordpress
    I have analysed the code of the animation being rendered on my Wordpress site, but the CSS coordinates all correspond to the parameters inside EA.
    I've also installed the Edge Suite plug on a different Wordpress installation (a complete different site) of mine, and the results are even worse. It seems like the origin of some elements is being tossed around space.
    That said, I'm clueless.

  • How can I get all prctr ( profit centers ) ?

    While creating function module,
    I have created import parameter as 'ZIMPORT_PRCTR' for Profit Center
    ( cepc-prctr ) in my zfunction module .
    It takes( imports ) input of multiple values Profit Center.
    Next what I need to do is, if end user enters multiple values of profit center
    ( IF ZIMPORT_PRCTR[] IS NOT INITIAL. )
    Then…  I have to use user entered values for picking up some other data from other tables.
    Ques). IF user don’t enter any profit center value, then
    I need to take all profit centers into consideration and pick up other data from other tables  .
    How can I get all profit centers ( if user does’t enters any value )
    And I don't have any values to use in my where condition ?
    Could you please help me ?

    create one structure in Se11 like
    profit center low
    profit center high
    option
    sign ( Like select-option ,see the rsparams structure),use this strucire in Function module ..
    when compare the data in select query ,in where condition use as in operator,if user does not enter any value ,it gets the all the value from table.

Maybe you are looking for