I am using a custom cell inside my table view. I have a view and I have a button inside that view that when the cell loads it checks if the array contains a labels text inside the cell. When I try get the text of a label it returns an empty value, if I click the button which has the same method to get the text contained it works just fine and gives me the text of the label.
Attached is the code
#import "TableViewCellSchedule.h"
@implementation TableViewCellSchedule
@synthesize name = _name;
@synthesize time = _time;
@synthesize pic = _pic;
@synthesize text = _text;
@synthesize scheduleID = _scheduleID;
NSMutableArray *favid;
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
favid = [[NSMutableArray alloc] init];
NSMutableArray *temparray = [userDefaults objectForKey:@"favid"];
if(temparray.count > 0){
favid = [temparray mutableCopy];
if([temparray containsObject:self.scheduleID.text]){
NSLog(@"set image here, id is: %@", self.scheduleID.text);
}
else{
NSLog(@"change image back here, id is: %@", self.scheduleID.text);
}
}
NSLog(@"welcome, array is: %@", favid);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)addfav {
if([favid containsObject:self.scheduleID.text]){
NSLog(@"contained already");
}
else{
NSLog(@"not contained");
[favid addObject:self.scheduleID.text];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:favid forKey:@"favid"];
[userDefaults synchronize];
}
//NSLog(@"schedule id is: %@", self.scheduleID.text);
//NSLog(@"fav log: %@", favid);
}
@end