UA-17470720-3

Jump to content


Photo
- - - - -

Push Empty Detail Controller--Mimic STV Add Item

view-controllers core-data

  • Please log in to reply
11 replies to this topic

#1 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 17 January 2014 - 01:24 PM

I have core data project with standard UITableViewController. I want to "push" an empty STV detailview controller mimicing the following STV code:

 

SCArrayOfObjectsSection *mySection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];

[mySection dispatchEventAddNewItem];

 

 

Searching through the forums I found the following code:

 

// this is your own custom method that you should call from your code
- (void)displayDetailViewForObject:(NSObject *)object withDefinition:(SCDataDefinition *)definition
{
  SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
  detailVC.navigationBarType = SCNavigationBarTypeEditRight;
  [detailVC.tableViewMode
generateSectionsForObject:object withDefinition:definition];

  
 
// assuming current view controller is inside a UINavigationController
  [self.navigationController pushViewController:detailVC animated:YES];
}

 

And this code:

 

- (void)myCustomButtonTapped
{
SCEntityDefinition *subsetDef = ...; // define the subset attributes here
SCTableViewSection *detailSection = [self.tableViewModel.activeDetailModel sectionAtIndex:0];

SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
[detailView.tableViewModel generateSectionsForObject:detailSection.boundObject withDefinition:subsetDef];

[self.tableViewModel.activeDetailModel.viewController.navigationController pushViewController:detailVC animated:TRUE];
}

 

Two snippets appear to be same.

 

I have implemented both and in both cases they push a "blank" SCTableViewController but neither generates the empty sections for the SCEntityDefinition.

In other words I am trying to add new item using STV from standard UITableViewController through "Add" button.

 

Would appreciate if anyone has any thoughts.

 

Thanks

 

TRG

 

 

 

 

 



#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 17 January 2014 - 03:10 PM

hey Todd

 

so firstly, what do you mean by "standard UITableviewcontroller"?? are you saying you have a normal UITableView that was not generated by STV ??

 

if you set break points along your code, are any items NIL, like the tableviewmodel etc?

 

if you are just wanting to use STV for creating a new item, you still need to build the whole property definitions etc.. hence the questions above to know what your doing exactly 


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 17 January 2014 - 04:53 PM

Oz,

 

Yes, I am using a standard apple UITableViewController in part of my development app. I am trying to push a SCTableView (empty) using a SCEntityDescription interfacing with coredata to create a new item.

The reason I am using a standard apple UITableViewController is because I have some specialized search characteristics I cannot achieve with a SCTableViewController.

 

So if I was using a SCTableViewController I could just hit the "+" button and a new empty SCTableViewModel (detailedview)  would launch (with the applicable sections and cells) for the SCEntityDefinition I am using.

 

However, using the above code, with the SCEntityDescription I am using, the empty cells/sections are not being created when I push the SCTableViewController detailVC, just a blank view controller with the navigation controller.

 

I don't know if that makes sense. In simplistic terms I guess, what I am looking to create is an empty detailcontroller using predefined scentitydefinition

 

Thanks



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 17 January 2014 - 06:18 PM

the first code sample you showed should do the job

- (void)displayDetailViewForObject:(NSObject *)object withDefinition:(SCDataDefinition *)definition
{
  SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
  detailVC.navigationBarType = SCNavigationBarTypeEditRight;
  [detailVC.tableViewModel generateSectionsForObject:object withDefinition:definition];
  
  // assuming current view controller is inside a UINavigationController
  [self.navigationController pushViewController:detailVC animated:YES];
}

so can you show the code you are trying where this is not working


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 17 January 2014 - 08:08 PM

Oz,

 

here is the code I implemented and all it does is push a empty detailviewcontroller....

 

- (void)myCustomButtonTapped

{

    

    // Get managedObjectContext from application delegate

    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];

    NSLog(@"localContext %@,",localContext);

    

    SCEntityDefinition *subsetDef =[SCEntityDefinition definitionWithEntityName:@"testEntity" managedObjectContext:localContext propertyNamesString:@"Identifiers:(test)"];

    

    [self displayDetailViewForObject:localContext withDefinition:subsetDef];

 

}

 

- (void)displayDetailViewForObject:(NSObject *)object withDefinition:(SCDataDefinition *)definition

{

    SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

    detailVC.navigationBarType = SCNavigationBarTypeEditRight;

    [detailVC.tableViewModel generateSectionsForObject:object withDefinition:definition];

    

    // assuming current view controller is inside a UINavigationController

    [self.navigationController pushViewController:detailVC animated:YES];

}

 

Here's the deal OZ--I want to create a new item in the testEntity, not edit a current one....



#6 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 17 January 2014 - 08:20 PM

what happens if you change this line

 [detailVC.tableViewModel generateSectionsForObject:object withDefinition:definition];

to

 [detailVC.tableViewModel generateSectionsForObject:object withDefinition:definition newObject:YES]; 

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#7 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 18 January 2014 - 07:48 AM

Ozie,

 

Tried that approach-- did not work.

 

What I successfully did to resolve the problem is create a new SCTableViewController. Then in ViewLoad() added the SCEntityDefinition plus following code:

 

//**********// NEW CODE //*******************//

    //This code launches STV in add mode with empty cells

    

    NSObject *myObject = nil;

    

    if (myObject == nil) {

        

        

        myObject = [NSEntityDescription

                         insertNewObjectForEntityForName:@"testEntity"

                         inManagedObjectContext:localContext];

        

        [self.tableViewModel generateSectionsForObject:myObject withDefinition:testDef];

 

}

 

The above I gleaned from early post buried in the forums.....

 

Works like a charm for anyone who is interested in launching STV Empty DetailView for adding records or launching DetailView for editing records using the below code with string or number predicate (uncomment the necessary lines):

 

 

//    //**********// NEW CODE //*******************//

//    //This code launches STV in detailviewcontroller mode

    

//    testEntity *newTest = appDelegate.myGlobaTest;

//    

//    NSNumber *number = @([myStrTestID intValue]);

//    

//    

//    //NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"testID == %@", mytestID];

//    

//    NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"testID == %@", number];

//    

//    

// SCDataFetchOptions *dataFetchOptions = [SCDataFetchOptions options];

// dataFetchOptions.filter = TRUE;

// dataFetchOptions.filterPredicate = myPredicate;

//

//  SCDataStore *store = [poleDef generateCompatibleDataStore];

// NSArray *array = [store fetchObjectsWithOptions:dataFetchOptions];

//

// NSManagedObject *mainObject = nil;

// if(array.count)

// mainObject = [array objectAtIndex:0];

//

// self.tableViewModel = [[SCTableViewModel alloc] initWithTableView:self.tableView];

// [self.tableViewModel generateSectionsForObject:mainObject withDefinition:testDef newObject:NO];

//  self.tableViewModel.editButtonItem = self.editButtonItem;

 

 The variable "appDelegate.myGlobaTest" is global variable used to pass selected object through app.


  • wizgod likes this

#8 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 18 January 2014 - 02:10 PM

hahah... i thought you were already passing an inserted object.. but i now see you were passing just the managedobjectcontext :) i should have looked harder at your code;)


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#9 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 27 January 2014 - 03:48 PM

i use basically the same code today.. but none of the section actions and other actions for the item, like did update, ever fire

 

hmm??


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#10 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 27 January 2014 - 05:00 PM

Oz,

 

Which code are you testing this:

 

[detailVC.tableViewModel generateSectionsForObject:object withDefinition:definition newObject:YES];

 

--which I figured out about the same time you responded, or the code I posted above your 18 January 2014 post?



#11 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 27 January 2014 - 05:06 PM

i get everything to load and show just fine.. i just can't get any actions to fire off

 

SCTableViewController *tvc = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    tvc.navigationBarType = SCNavigationBarTypeDoneRightCancelLeft;
    tvc.title = NSLocalizedString(@"Task", nil);

    NSObject *myObject = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:moContext];
    [tvc.tableViewModel generateSectionsForObject:myObject withDefinition:taskDef];
    
    
    tvc.tableViewModel.sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
    {
        NSLog(@"detailModelWillPresent");
    };

it never logs anything out.. and all the other actions i have coded also never fire


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#12 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 27 January 2014 - 06:50 PM

Oz,

 

I never got that to work either so what I did was this--pushed a view controller from selected row and then launched the view controller in detail mode using my above code:

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{


    
        self.selectedTest = [self.fetchedResultsController objectAtIndexPath:indexPath];
 

            NSLog(@"MasterTVC: '%@ %@' selected on Master View",self.selectedTest.iTestID, self.selectedTest.iWC);
       
         

//pass selected item


          GHAppDelegate *appDelegate = (GHAppDelegate *)[[UIApplication sharedApplication] delegate];
 

       
   appDelegate.myGlobalTest = self.selectedTest;


          NSLog(@"appDelegate.myGlobalTest %@,",appDelegate.myGlobalTest);
 

       [delegate testChangedOnMaster:self];


        
        
        TestController * vc = [[TestController alloc]
  initWithNibName:Nil bundle:nil];
 

       
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Details" style:UIBarButtonItemStyleBordered target:nil action:nil]; 

       
        [self.navigationController pushViewController:vc animated:YES];


   
}

 


Edited by TODD GARLAND, 27 January 2014 - 06:52 PM.






Also tagged with one or more of these keywords: view-controllers, core-data

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users