I've looked through all the related questions and I still can't get this working.
I made a custom cell .xib (foodCell.xib) and set it's file owner to foodCell.h. I have also set the identifier to foodCell.
So far all I have in the custom cell is a custom label - priceLabel
. The problem I'm having is I can't seem to set a value to the custom label or display it at runtime.
Here is my foodcell.h file:
#import <Parse/Parse.h>
@interface foodCell : PFTableViewCell
@property (weak, nonatomic) IBOutlet NSObject *foodCell;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@end
Here is where in my tableViewController file I configure the custom cell. All of the other label.text calls work fine, and the image displays.
My NSLOG
call returns null
.
Why can't I set or display this custom label?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"foodCell";
foodCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[foodCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.textLabel.text = [object objectForKey:@"foodName"];
cell.detailTextLabel.text = [object objectForKey:@"foodDescription"];
cell.imageView.file = [object objectForKey:@"foodImage"];
NSString *myString = @"TEST";
cell.priceLabel.text = myString; //[object objectForKey:@"foodPrice"];
NSLog(cell.priceLabel.text);
cell.detailTextLabel.numberOfLines=0; // line wrap
cell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
return cell;
}
Register you Nib
with your UITableView
in viewDidLoad
[self.tableView registerNib:[UINib nibWithNibName:@"foodCell" bundle:nil] forCellReuseIdentifier:@"foodCellIdentifier"];
Then in cellForRowAtIndexPath
: create cell like below.
static NSString *CellIdentifier = @"foodCell";
foodCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.