core data subclass with collectionViewCell - ios

In my collectionView based app i want to cache the last 100 cells loaded, and i think best way for me is to work with core data.
I already have a custom class for UICollectionViewCell, and obviously all the cells are objects of this class. it's look kind of like this:
#interface Cell : UICollectionViewCell
#property (strong, nonatomic) NSString *cellFacebookId;
#property (strong, nonatomic) NSString *cellMail;
#property (strong, nonatomic) NSString *cellAddId;
#property (strong, nonatomic) NSString *cellCategory;
#property (strong, nonatomic) IBOutlet UIImageView *cellBackImg;
#property (strong, nonatomic) IBOutlet UIImageView *titleBarImage;
#end
Now I've created an entity named Cell, with same attributes. can i create a NSManagedObject subclass that will replace my original "Cell" class and still use it as UICollectionViewCell custom class?

You can't use a subclass of NSManagedObject as a UICollectionView cell. It has to be a subclass of UICollectionViewCell. Besides UICollectionView reuses cells by caching them.

Related

selecting UITextField in custom cell crashes

I'm trying to create a form like view using custom cells in uitableview. I have 3 custom cells, one with 6 UITextFields, one with just one, and one with a UITextView. It displays perfectly, and scrolls up and down with no problems. My problem is that whenever I select anything, either a textField or TextView it crashes with EXC_BAD_ACCESS. My break point shows that the textfields are not nil.
Any ideas about what may be causing my crash?
custom cell - properties in .h file - delegates set in custom cell class
#interface CandidateInfo1Cell : UITableViewCell
#property (nonatomic, strong) IBOutlet UITextField *firstNameText;
#property (nonatomic, strong) IBOutlet UITextField *lastNameText;
#property (nonatomic, strong) IBOutlet UITextField *cityText;
#property (nonatomic, strong) IBOutlet UITextField *stateText;
#property (nonatomic, strong) IBOutlet UITextField *emailText;
#property (nonatomic, strong) IBOutlet UITextField *phoneText;
#end
registering my nib:
UINib *infoCellNib = [UINib nibWithNibName:REUSE_INFO_CELLID bundle:[NSBundle bundleForClass:[InfoCell class]]];
[self.listTable registerNib:infoCellNib forCellReuseIdentifier:REUSE_INFO_CELLID];
cellForRowAtIndexPath:
InfoCell *cell = [tableView dequeueReusableCellWithIdentifier:REUSE_INFO_CELLID];
[self configureInfoCell:(InfoCell *)cell forRowAtIndexPath:indexPath];
return cell;

UITableViewCell is loading filler content instead of programmatic input?

I have created a custom UITableViewCell that contains 3 UILabels and a UIImageView. I am setting this up via storyboards and have a UITableView class that is connected to the table cell. In that class I am wanting to handle the different UI objects and have the option to pass in information from my view controller.
Here is the .h of my table cell view class
#property (retain, nonatomic) IBOutlet GBPathImageView *ProfileThumbnailImageView;
#property (weak, nonatomic) IBOutlet UILabel *profileDisplayNameLabel;
#property (weak, nonatomic) IBOutlet UILabel *profileUniversityNameLabel;
#property (weak, nonatomic) IBOutlet UILabel *profileNumberOfStringsLabel;
#property (strong, nonatomic) NSString *profileDisplayName;
#property (strong, nonatomic) UIImage *profileThumbnailImage;
#property (strong, nonatomic) NSString *profileUniversityName;
#property (nonatomic) NSUInteger profileNumberOfStrings;
- (id)initWithProfileImage:(UIImage *)profileImage
displayName:(NSString *)displayName
universityName:(NSString *)universityName
numberOfUserStrings:(NSUInteger)numberOfStrings;
As you can see I have a property outlet that all of the storyboard objects are connected to. I also have properties for each piece of necessary information. In my view controllers
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method I am wanting to instantiate this custom cell with information that I pass in. I am wanting to set the information properties with the correct info and have it be setup in the view class.
Here is the code inside the previously mentioned method:
static NSString *cellIdentifier = #"UserProfileCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if ([cell isKindOfClass:[StringrUserTableViewCell class]]) {
StringrUserTableViewCell * userProfileCell = (StringrUserTableViewCell *)cell;
userProfileCell.profileDisplayName = #"Alonso Holmes";
//userProfileCell.profileDisplayNameLabel.text = #"User Name";
}
I have two lines there, one is setting the information property for the name, and I have it in the view's .m file to set its text to that properties name. The problem that is happening is that the profileDisplayName property is null at the time it tries to set that UILabels text. How can I set this information at a time so that it will be there before the cell is loaded or when it's initially loading? You can also see a commented out line where I directly set the text of the UILabel right there. I would prefer not to do it this way because I want to leave the abstraction/logic to the view's class. The image view I setup is custom so it takes more code.
You are trying to set your text in profileDisplayName which is NSString type not a UILabel class. ( see #property (strong, nonatomic) NSString *profileDisplayName; ).
Change your line of code:
here is the problem
userProfileCell.profileDisplayName = #"Alonso Holmes"; //Use Label Object instead of NSString

iOS objects return nil soon after creation

so I'm writing Obj-C for iOS, and something "strange" is happening..
I have an MVC, with a UITableView (private):
#interface MVC ()
#property (strong, nonatomic) IBOutlet UITableView *tableView;
#property (strong, nonatomic) CellVC *cell1;
#property (strong, nonatomic) CellVC *cell2;
#end
I load the table view up with a few custom cells. My custom cell class is actually a UIViewController... so I instantiate a few, and set cell.contentView to the corresponding CellVC.view inside the tableView:cellForRowAtIndexPath: method. My custom cell class:
#interface CellVC : UIViewController
#property (strong, nonatomic) IBOutlet UIKnob *knob1;
#property (strong, nonatomic) IBOutlet UIKnob *knob2;
#property (strong, nonatomic) IBOutlet UIKnob *knob3;
#property (strong, nonatomic) IBOutlet UIKnob *knob4;
#end
In case you're wondering, I've written a subclass of UIControl named UIKnob...
In CellVC's viewDidAppear: method, I've set a breakpoint to check the values of every knob. Each knob is non-nil, so I am happy... they have all been created.
My goal is to set MVC as the delegate of each knob. (4 knobs for each cell)
If I set a breakpoint anywhere in MVC, the value of each knob is nil??...
cell1.knob1.delegate = self;
will not work because the knobs only exist inside CellVC.m ...
Any ideas??

CustomView UILabel Set Text Crash

I have a custom view - DetailSubView.h with labels
#property (retain, nonatomic) UILabel *titleLabel;
#property (retain, nonatomic) UILabel *descHeaderLabel;
On custom UICollectionViewCell, i have
#property (strong, nonatomic) DetailSubView *detailView;
When I set text, i received unrecognized selector error.
[self.detailView.titleLabel setText:#"text"];
That's because your titleLabel is declared in DetailView but you're trying to access it from a class of type DetailSubView. It cannot access the getter method for your property on DetailSubView since you don't have it declared there.

CustomTableViewCell with xib. I can't wire up the labels to the custom state table cell

I've just created CustomTableViewCell.xib. Then I created class CustomTableViewCell with IBOutlets. In the identity inspector I changed the type to my CustomTableViewCell.
#interface CustomTableViewCell : UITableViewCell
{
IBOutlet NSString *placeName;
IBOutlet NSString *address;
IBOutlet NSString *distance;
}
#property (nonatomic, retain) IBOutlet NSString *placeName;
#property (nonatomic, retain) IBOutlet NSString *address;
#property (nonatomic, retain) IBOutlet NSString *distance;
#end
But I can't wire up the labels to the custom state table cell. Please see the screenshot.
Maybe you need to use:
IBOutlet UILabel * placeNameLabel
...
instead. Then, set the text in the label view.

Resources