UITableViewCell subclassing problem
I have a class A that inherits from UITableViewCell (for setting up a table cell). It has x members which are UILabel.
Now, if I want to set values such as axtext = "some text" in the cellForRowAtIndexPath method, I get the compiler error "error for member x in a cell that is of type UITableViewCell".
Could you please let me know how I can fix this problem?
Thanks.
+1
a source to share
3 answers
First, make sure your property is defined correctly:
@interface A : UITableViewCell {
UILabel *x;
}
@property (nonatomic, retain) IBOutlet UILabel *x;
@end
Then make sure you include Ah in your table datasource, and make sure you select cell 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;
}
+2
a source to share