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.
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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow