tags:

views:

209

answers:

3

Hi All,

I have a class A that inherits UITableViewCell (to customize a table cell). It has members say x which is a UILabel.

Now, if I want to set values like a.x.text ="some text" in the cellForRowAtIndexPath method, I am getting compiler error "error for member x in cell which is of non-class type UITableViewCell".

Could you please let me know how can I fix this problem?

Thanks.

A: 

Be sure to add x as a property to your subclass:

@interface ACell : UITableViewCell {
      UILabel *X;
}

@property (readonly, nonatomic) UILabel* X;
drewh
A: 

Try using:

[[a x] setText:@"your text];

And see what happens.

Pablo Santa Cruz
+1  A: 

First, make sure your property is defined correctly:

@interface A : UITableViewCell {
  UILabel *x;
}

@property (nonatomic, retain) IBOutlet UILabel *x;

@end

Then make sure you've included A.h in your table view datasource, and make sure you're casting the cell to type A:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *cellIdentifier = @"cell";
  A *a = (A *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  if (a == nil) {
    a = [[A alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
  }
  a.x.text = @"some text";
  return a;
}
pix0r
x is a property of class A, and I am following the code as above. I have included A.h in the viewcontroller.m file (where the cellForRowAtIndexPath method is). Could you let me know how to included A.h in my table view datasource?
ebaccount
The tableView:cellForRowAtIndexPath: is a UITableViewDataSource method - so if you have included A.h in your view controller, that's all I meant.Make sure that you are casting your cell to type A* and not UITableViewCell*, because UITableViewCell obviously doesn't have your custom property.
pix0r
Thanks for your reply. It was my mistake. I was using UITableViewCell *cell instead of A * cell. It is fixed now.
ebaccount