Question

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.

Was it helpful?

Solution

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;
}

OTHER TIPS

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

@interface ACell : UITableViewCell {
      UILabel *X;
}

@property (readonly, nonatomic) UILabel* X;

Try using:

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

And see what happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top