I looked around and there are many examples on how to do this, but I am still not getting it.
I have a list where I am listing journal entries which I want to display a title, date created and few other things. I want to use an XIB to design a cell, so UX designer can modify it and pixel push it.
So, this is how i setup the xib:
Then I made a class that this xib cell points to and I added two properties to it:
@property (atomic, weak) IBOutlet UILabel* titleLabel;
@property (atomic, weak) IBOutlet UILabel* dateLabel;
I want to be able to set these when I create these cells.
In the view that has the list table I do this: In -(void) viewDidLoad
[self.tableView registerNib:[UINib nibWithNibName:@"DreamListTableViewCell" bundle:nil] forCellReuseIdentifier:@"DreamListCell"];
And in - (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I do this:
static NSString *MyIdentifier = @"DreamListCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier forIndexPath:indexPath];
The problem is that the app crashes if I setup IBOutlets in the cell xib, because I guess the owner is really nil when it is initialized, but I am actually not sure. How could I modify those two properties if I can't connect them in interface builder? What should I do differently?
Also, I am not using storyboards. I am using this as a guide: Chapter 21. Table Views and Collection Views
I apologize for sort of duplicate question, I am just not getting it. Halp!
Edit: Outlet screenshot:
Edit #2: If I remove outlet connections in the cell xib i see this:
let cell = collectionView. dequeueReusableCell(withReuseIdentifier: “collectionCell”, for: indexPath) in the place where you need the instance of the cell view. Then you can drag all the reference from storyboard to “yourCustomCell. swift” to do what ever you want for the view(etc.
Don't use File's Owner to set the relationships to IBOutlets. Change the class of the cell and use that instead (might be tricky to make the connections on some Xcode versions, but is doable).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With