Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Zelda

macrumors member
Original poster
Aug 10, 2014
39
2
Hello ,
I'm using latest iOS 8 SDK and Swift.
How can i get the Entity Index-row or section property when i select from a tableview?
I tried the following,
Code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showDetail" {

            if let indexPath = self.tableView.indexPathForSelectedRow() {

	    let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as Event

                    }

               (segue.destinationViewController as DetailViewController).detailItem = object

                }

How would i retrieve the index row or section for the core data entity ?..
Any hints or advice is appreciated.
Thanks
Z
 
Last edited:
Hello ,
I'm using latest iOS 8 SDK and Swift.
How can i get the Entity Index-row or section property when i select from a tableview?
I tried the following,
Code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showDetail" {

            if let indexPath = self.tableView.indexPathForSelectedRow() {

	    let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as Event

                    }

               (segue.destinationViewController as DetailViewController).detailItem = object

                }

How would i retrieve the index row or section for the core data entity ?..
Any hints or advice is appreciated.
Thanks
Z

Not sure how you do it in Swift, but you can create an NSArray of your Core Data entries using NSFetchRequest and executeFetchRequest. After that you should be able to load that into a table view and select your desired index.
 
Thanks for the reply,
It is not quite what i need, the tableview is already populated in the masterView.
When i tap on the tableview and seque to the detailView i can send the specific entity's attribute's over to the detailView, the problem is in the detailView.
I want to edit the attribute and save or update the Model with the following code:
Code:
	let fetchRequest = NSFetchRequest(entityName: "Event")

        if let fetchResults = managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) as? [Event] {        

                fetchResults[0].attribute1 = value1

                fetchResults[0].attribute2 = value2

          // i need the index row for the array fetchResults[0].attribute1 = value1  

}
I need to grab the index row for the entity record that the user taps on the tableView in the MasterViewController.
Thanks
Z
 
I found something that might work, just haven't got it running yet.
Code:
if let indexPath = self.tableView.indexPathForSelectedRow() {
               
                let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as Event
                
                 let indexPathEntity = object.indexOfAccessibilityElement(managedObjectContext?)

So the first line gets the index of the tableView cell selected.
And the second line gets the Entity core data record for that tableView cell index.
I need the third line to grab the index of the Entity the user selected, to use in the detail view.
thanks
Z
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.