Why is my synthesized NSNumber property not set?

Discussion in 'iOS Development' started by masaj, May 8, 2009.

  1. masaj

    masaj New Member

    Joined:
    Apr 27, 2009
    Messages:
    13
    Likes Received:
    0
    I have
    Code:
    #import <UIKit/UIKit.h>
    
    @interface GridRow : UITableViewCell {
        NSMutableArray *columns;
        NSNumber* colWidth;
    }
    
    - (void) addColumn: (NSString*)text;
    - (void) drawRect: (CGRect)rect;
    
    @property (nonatomic, retain) NSNumber* colWidth;
    
    @end
    
    
    When I call from another class:
    Code:
    cell.colWidth = [NSNumber numberWithInt: 80];
    
    cell.colWidth is still 0.

    Am I not allowed to set an Object reference/pointer using the dot notation from a synthesized property?
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    There is no colWidth in UITableViewCell.

    there is rowHeight in UITableView where it can be self.tableView.rowHeight

    Did you tell in other class to load GridRow instead UITableViewCell?
  3. masaj

    masaj New Member

    Joined:
    Apr 27, 2009
    Messages:
    13
    Likes Received:
    0
    No. I'm definitely creating my GridRow. Was wondering if maybe there was some gotcha with synthesizing NSNumber that I don't know about.
  4. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    The other thing I can think of that you're missing a
    Code:
    @synthesized colWidth;
    in your GridRow.m file.

    Btw:
    What are you doing? Subclassing a UITableViewCell is, in most cases, a bad idea...
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    ZOMG!!!! In almost 100% of all cases, subclassing UITableViewCell is one of the best things you can ever do. Ever. I even use subclasses of my own UITableViewCell subclasses.


    Anyway, to the OP, the problem is that it appears you are feeding an autoreleased object to your property, which generally won't work. You could override your setter and store a copy of the number, which wouldn't necessarily be a bad idea.

    Code:
    //  YourObject.h
    @property (nonatomic, retain, setter=setColWidth:) NSNumber* colWidth;
    
    // YourObject.m
    @synthesize colWidth
    /* Later in your class implementation */
    - (void)setColWidth:(NSNumber *)number {
    colWidth = [number copy];
    }
    
  6. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    I know, how we expected to put 3 UILabel in one cell? You can't do that without subclasses it.

Share This Page