Getting error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance'…
The SIGABRT came on the else cell.textLabel.text = @"Blank"; line of:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {UITableViewCell *cell = nil;
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pattern" inManagedObjectContext:context];
// Edit the sort method.
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"patternName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor, nil] autorelease];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setEntity:entity];
_patterns = [context executeFetchRequest:fetchRequest error:nil];
[fetchRequest release];
NSArray *names = [_patterns valueForKey:@"patternName"];
NSArray *urls = [_patterns valueForKey:@"patternUrl"];
if (names!= nil) {
cell.textLabel.text = [names objectAtIndex:indexPath.row];
}
else cell.textLabel.text = @"Blank";
cell.detailTextLabel.text = [urls objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
I can add a defined record (copies the url of the page the user is viewing inserting the URL into both the url field and the name attributes). Editing or creating a new record pops a ModalViewController that presents (for existing records) and captures data in textfields (for new records). Selecting the save crashes, changes only the record of the last-added defined record even if it has been edited and adds that as a new record, keeping the old one. I think somethings wrong with my keeping track of the number of cells.
Any suggestions would be most appreciated.
What you get from executeFetchRequest is array of objects not attributes. You need to loop through array of objects and get attributes from each of them
This
Should become