Hi all! I would ask for your help. I'm developing an app that has:
A. Item.h
B. MainTableViewController.m
Simply I want that a CategoryDetailsViewController shows tipTextField. So, in CategoryDetailsViewController.h I set:
and in CategoryDetailsViewController.m:
but when from a row I want to see detailed text of category (i.e. tip1 for Category1) my app crashes for [super viewDidLoad], with [NSObject(NSObject) doesNotRecognizeSelector:]:
I would achieve that user taps on a row (that is a category) and a DetailsViewController appears. Here, with "previous" and "forward" buttons he can navigate through items for each category.
Any help? Feel free to ask for more code if needed, thanks in advance!
A. Item.h
Code:
@interface Items : NSObject
@property (nonatomic, strong) NSString *categoryName; // category's name
@property (nonatomic, strong) NSString *categoryImage; // image showed on the left of the table row
@property (nonatomic, strong) NSString *tipTextField; // text displayed in a single tip
B. MainTableViewController.m
Code:
#import "Items.h"
#import "CategoryTableViewCell.h"
{
NSArray *categoryArray;
NSArray *tipsArray;
}
// Initialize items of category1
Items *tip1 = [Items new];
tip1.tipTextField = @"text goes here";
//Create tips array
tipsArray = [NSArray arrayWithObjects: tip1, tip2, ..., nil];
// Initialize the category array
Items *category1 = [Items new];
category1.categoryName = @"Category1";
category1.categoryImage = @"image.png";
category1.tipTextField = tipsArray [0];
//ADDED TEXT AFTER EDITING POST
categoryArray = [NSArray arrayWithObjects: category1, category2, category3, category4, category5, category6, category7, category8, nil];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
} else {
return [categoryArray count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomTableCell";
CategoryTableViewCell *cell = (CategoryTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[CategoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Display category in the table cell
Items *item = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
item = [searchResults objectAtIndex:indexPath.row];
} else {
item = [categoryArray objectAtIndex:indexPath.row];
}
cell.nameLabel.text = item.categoryName;
cell.thumbnailImageView.image = [UIImage imageNamed:item.categoryImage];
return cell;
}
//Set row height at 52
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 52;
}
//View details of selected category
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showTipDetail"]) {
NSIndexPath *indexPath = nil;
Items *item = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
item = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
item = [categoryArray objectAtIndex:indexPath.row];
}
CategoryDetailsViewController *destViewController = segue.destinationViewController;
destViewController.item = item;
}
}
Simply I want that a CategoryDetailsViewController shows tipTextField. So, in CategoryDetailsViewController.h I set:
Code:
#import "Items.h"
@property (weak, nonatomic) IBOutlet UITextView *tipTextField;
@property (nonatomic, strong) Items *item;
and in CategoryDetailsViewController.m:
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
tipTextField.text = self.item.tipTextField;
but when from a row I want to see detailed text of category (i.e. tip1 for Category1) my app crashes for [super viewDidLoad], with [NSObject(NSObject) doesNotRecognizeSelector:]:
I would achieve that user taps on a row (that is a category) and a DetailsViewController appears. Here, with "previous" and "forward" buttons he can navigate through items for each category.
Any help? Feel free to ask for more code if needed, thanks in advance!
Last edited: