2016-04-28 9 views
0

私はそれは私に私がクラスの隣の識別子を必要とするエラーが発生します。このオプションこのオプションにはどの識別子を追加する必要がありますか?

var mapRegion : MKCoordinateRegion 

を追加したい:

class TableViewController: UITableViewController, NSFetchedResultsControllerDelegate, 

その識別子は何ですか?あなたはvar mapRegion : MKCoordinateRegionを宣言しているが、任意の初期化子またはデフォルト値を持たない

import UIKit 
import CoreData 
import MapKit 

class TableViewController: UITableViewController, NSFetchedResultsControllerDelegate, { 

let moc = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext 
var frc : NSFetchedResultsController = NSFetchedResultsController() 

var mapRegion : MKCoordinateRegion 


func fetchRequest() -> NSFetchRequest { 

    let fetchRequest = NSFetchRequest(entityName: "Item") 
    let sortDescriptor = NSSortDescriptor(key: "name", 
              ascending: true) 
    fetchRequest.sortDescriptors = [sortDescriptor] 
    return fetchRequest 
} 
func getFRC() -> NSFetchedResultsController { 

    frc = NSFetchedResultsController(fetchRequest: fetchRequest(), managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil) 
    return frc 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    frc = getFRC() 
    frc.delegate = self 

    do { 
     try frc.performFetch() 
    } catch { 
     print("Failed to perform initial fetch.") 
     return 
    } 

    self.tableView.rowHeight = 480 
    self.tableView.backgroundView = UIImageView(image: UIImage(named: "flatgrey2")) 
    self .tableView.reloadData() 
} 

override func viewDidAppear(animated: Bool) { 
    frc = getFRC() 
    frc.delegate = self 

    do { 
     try frc.performFetch() 
    } catch { 
     print("Failed to perform initial fetch.") 
     return 
    } 
    self .tableView.reloadData() 
} 


override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 


override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    let numberOfSections = frc.sections?.count 
    return numberOfSections! 

} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    let numberofRowsInSection = frc.sections?[section].numberOfObjects 

    return numberofRowsInSection! 

    //return 0 

} 



override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 

    if indexPath.row % 2 == 0 { 
     cell.backgroundColor = UIColor.clearColor() 
    } else { 
     cell.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.2) 
     cell.textLabel?.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.0) 
     cell.detailTextLabel?.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.0) 
    } 


    // Configure the cell... 
    cell.textLabel?.textColor = UIColor.darkGrayColor() 
    cell.detailTextLabel?.textColor = UIColor.darkGrayColor() 

    let item = frc.objectAtIndexPath(indexPath) as! Item 
    cell.textLabel?.text = item.name 
    cell.imageView?.image = UIImage(data: (item.image)!) 

    return cell 
} 





/* 
// Override to support conditional editing of the table view. 
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return false if you do not want the specified item to be editable. 
    return true 
} 
*/ 


// Override to support editing the table view. 

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 

    let managedObject : NSManagedObject = frc.objectAtIndexPath(indexPath) as! NSManagedObject 
    moc.deleteObject(managedObject) 

    do { 
     try moc.save() 
    } catch { 
     print ("Failed to save.") 
     return 
    } 
} 

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { 
    tableView.reloadData() 
} 






/* 
// Override to support rearranging the table view. 
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { 

} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return false if you do not want the item to be re-orderable. 
    return true 
} 
*/ 


// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
    if segue.identifier == "edit" { 

     let cell = sender as! UITableViewCell 
     let indexPath = tableView.indexPathForCell(cell) 
     let itemController : AddEditVC = segue.destinationViewController as! AddEditVC 
     let item : Item = frc.objectAtIndexPath(indexPath!) as! Item 
     itemController.item = item 
    } 

} 

}

答えて

0

ファイルには、次のようになります。そのオプションにするには、ちょうどそれに?を追加し、そう宣言:

var mapRegion : MKCoordinateRegion? 
+0

ありがとうございました! –

1

変数は、それ以外の場合は、このエラーが表示されますと宣言されたときに値を持つ必要があります。変数var mapRegion : MKCoordinateRegionに値を割り当てます。値が後の段階で与えられた場合、つまり計算に依存する場合はこのようにオプションにします。mapRegion値の末尾に感嘆符を置くことで、いつでも変数をアンラップする必要があります。変数名。

+0

あなたの答えをありがとう! –

関連する問題