I'm calling method doSomething in my View Controller. The method is declared in my super and sub classes (these classes are for my 3 entities - 1 is parent of other 2). The super class is called SuperClass (not really but for sake of question). I've created an instance for the class called superClass.
[superClass doSomething];
The method returns a string, this string returned is supposed to be text that is entered by the user into a UITextField declared in the ViewController. I cannot get this to work. I had it working fine when everything was contained in the VC but now I'm having to use the entity classes where if no value is returned by the superclass, it looks in the subclass. The attribute is name that is being returned. I need to enter value in headingText (UITextField), have doSomething (method) return that value stored in superClass.name and then cell.displayText.text = superClass.name will display that value. Any and all help is super appreciated! Thanks!
SuperClass.m
SubClassA.m
ViewController.m
[superClass doSomething];
The method returns a string, this string returned is supposed to be text that is entered by the user into a UITextField declared in the ViewController. I cannot get this to work. I had it working fine when everything was contained in the VC but now I'm having to use the entity classes where if no value is returned by the superclass, it looks in the subclass. The attribute is name that is being returned. I need to enter value in headingText (UITextField), have doSomething (method) return that value stored in superClass.name and then cell.displayText.text = superClass.name will display that value. Any and all help is super appreciated! Thanks!
SuperClass.m
Code:
#import "SuperClass.h"
@implementation SuperClass
@dynamic name;
-(NSString *)doSomething
{
return self.name;
}
@end
SubClassA.m
Code:
#import "SubClassA.h" //SubClassA.h imports SuperClass.h
@implementation SubClassA
@dynamic body;
@dynamic heading;
-(NSString *)doSomething
{
[super doSomething];
return self.name;
}
@end
ViewController.m
Code:
- (IBAction)donePressed:(id)sender {
AppDelegate* appDelegate = ( AppDelegate* ) [ [UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
SuperClass *superClass = [NSEntityDescription
insertNewObjectForEntityForName:@"SuperClass"
inManagedObjectContext:context];
superClass.name = headingText.text; //headingText is UITextField
NSString *fromDoSomething = [superClass doSomething];
// I'm missing something here!
[superClass doSomething];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s",__FUNCTION__);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.font = [UIFont systemFontOfSize:19.0];
}
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
SuperClass *superClass = (SuperClass *)object;
superClass.name = superClass.doSomething;
cell.textLabel.text = superClass.name;
return cell;
}
Last edited: