error: request for member 'myLabel' in something not a structure or union

Discussion in 'iPhone/iPad Programming' started by PreethaAjayan, Jun 22, 2009.

  1. macrumors newbie

    Joined:
    May 22, 2009
    #1
    Hi,

    I got the error 'error: request for member 'myLabel' in something not a structure or union' i spend couple of hours with this.. please help me..

    the situation is,

    I created a custon tableview cell inherited from UITableViewCell

    code:
    Code:
    @interface CustomCell : UITableViewCell {
    	UIImageView *myImageView;
    	UILabel *primaryLabel;
    	UILabel *primaryLabel1;
    	UILabel *secondaryLabel;
    	UILabel *secondaryLabel1;
    	UILabel *myLabel;
    	int  customType;
    }
    @property (nonatomic,retain) UIImageView *myImageView;
    @property (nonatomic,retain) UILabel *primaryLabel;
    @property (nonatomic,retain) UILabel *primaryLabel1;
    @property (nonatomic,retain) UILabel *secondaryLabel;
    @property (nonatomic,retain) UILabel *secondaryLabel1;
    @property (nonatomic,retain) UILabel *myLabel;
    
    -(void)setCustomType:(int)n;
    
    @end
    In the implementation file synthesized all the labels
    Code :
    Code:
    #import "CustomCell.h"
    
    @implementation CustomCell
    @synthesize primaryLabel,primaryLabel1,secondaryLabel,myImageView,secondaryLabel1,myLabel;
    
    - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
        if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
            // Initialization code
    		primaryLabel = [[[UILabel alloc]init] autorelease];
    		primaryLabel1 = [[[UILabel alloc]init] autorelease];
    		secondaryLabel = [[[UILabel alloc]init] autorelease];
    		secondaryLabel1 = [[[UILabel alloc] init] autorelease];
    		myImageView = [[[UIImageView alloc]init] autorelease];
    		myLabel		=	[[UILabel alloc]init];
    		[self.contentView addSubview:primaryLabel];
    		[self.contentView addSubview:primaryLabel1];
    		[self.contentView addSubview:secondaryLabel];
    		[self.contentView addSubview:secondaryLabel1];
    		[self.contentView addSubview:myImageView];
    		[self.contentView addSubview:myLabel];
        }
        return self;
    }
    
    
    - (void)layoutSubviews {
    	[super layoutSubviews];
    	
    	CGRect contentRect = self.contentView.bounds;
    	CGFloat boundsX = contentRect.origin.x;
    	
    	switch (customType) {
    		case 2: //For Liability
    			 
    			 myImageView.frame = CGRectMake(boundsX+5 ,2, 24, 24);
    			 primaryLabel.frame = CGRectMake(boundsX+40 ,5, 150, 18);
    			 primaryLabel.font = [UIFont systemFontOfSize:15];
    			 
    			 secondaryLabel.frame = CGRectMake(boundsX+200 ,5, 95, 15);
    			 secondaryLabel.font = [UIFont systemFontOfSize:14];
    			 secondaryLabel.textAlignment = UITextAlignmentRight;
    			 break;			
    		case 3:
    			primaryLabel.frame			=	CGRectMake(boundsX+5 ,5, 170, 15);//25
    			primaryLabel.textAlignment	=	UITextAlignmentLeft;
    			primaryLabel.font			=	[UIFont boldSystemFontOfSize:15];
    			primaryLabel.backgroundColor = [UIColor greenColor];
    					
    			myLabel.frame				=	CGRectMake(primaryLabel.bounds.origin.x + 180 ,5, 115, 15);
    			myLabel.textAlignment		=	UITextAlignmentRight;
    			myLabel.font				=	[UIFont	boldSystemFontOfSize:15];
    			myLabel.backgroundColor		=	[UIColor	blueColor];
    			
    			secondaryLabel.frame		=	CGRectMake(boundsX+5 ,25, 170, 15);//15
    			secondaryLabel.textAlignment = UITextAlignmentLeft;
    			secondaryLabel.font			=	[UIFont boldSystemFontOfSize:12];
    			secondaryLabel.textColor	=	[UIColor redColor];
    			secondaryLabel.backgroundColor = [UIColor redColor];
    			
    			secondaryLabel1.frame		=	CGRectMake(secondaryLabel.bounds.origin.x + 180, 25, 115, 15);
    			secondaryLabel1.textAlignment = UITextAlignmentRight;
    			secondaryLabel1.font		=	[UIFont boldSystemFontOfSize:12];
    			secondaryLabel1.textColor	=	[UIColor redColor];
    			secondaryLabel1.backgroundColor = [UIColor blueColor];
    			break;
    		default:
    			break;
    	}
    	
    }
    
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    -(void)setCustomType :(int)n{
    	customType = n;
    }
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end

    Then in the controller class( in CellForRowAtIndexPath) ..
    Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    	static NSString *CellIdentifier = @"Cell";
    	CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    	if (cell == nil) {
    		cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    	}
    cell.customType = 3;
    [cell.textLabel setText:@"Mortgages"];
    					cell.backgroundColor = [UIColor lightGrayColor];
    					cell.indentationLevel = 2;
    					cell.selectionStyle = UITableViewCellSelectionStyleNone;
    					[cell.primaryLabel setHidden:YES];
    					[cell.secondaryLabel setHidden:YES];
    					[cell.secondaryLabel1 setHidden:YES];
    					[COLOR="Red"][cell.myLabel setHidden:YES];[/COLOR]
    }
    the error is in the line [cell.myLabel setHidden:YES]. but the same code like [cell.primaryLabel setHidden:YES];
    [cell.secondaryLabel setHidden:YES];
    [cell.secondaryLabel1 setHidden:YES]; works fine.

    please help me.... I am looking forward to hear from you....


    Regards,
    Preetha
     

Share This Page