Note that there are some explanatory texts on larger screens.

plurals
  1. POEntering Value in UITextField, using method from entity classes, need value to display in TableView
    text
    copied!<p>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. </p> <p>[superClass doSomething];</p> <p>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!</p> <p>SuperClass.m</p> <pre><code>#import "SuperClass.h" @implementation SuperClass @dynamic name; -(NSString *)doSomething { return self.name; } @end </code></pre> <p>SubClassA.m</p> <pre><code>#import "SubClassA.h" //SubClassA.h imports SuperClass.h @implementation SubClassA @dynamic body; @dynamic heading; -(NSString *)doSomething { [super doSomething]; return self.name; } @end </code></pre> <p>ViewController.m</p> <pre><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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload