2016-12-21 56 views
0

RxCoreData bindTo的TableView如何當我改變模型RxCoreData的UI不會更新

class ViewController: UIViewController { 

@IBOutlet weak var tableView: UITableView! 
@IBOutlet weak var addBarButtonItem: UIBarButtonItem! 

var managedObjectContext: NSManagedObjectContext! 

let disposeBag = DisposeBag() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    bindUI() 
    configureTableView() 

} 

func bindUI() { 

    addBarButtonItem.rx.tap 
     .map { _ in 
      Event(id: "1", date: Date(timeIntervalSince1970: 0)) 
    /* Change Date(timeIntervalSince1970: 1) */ 
     }.subscribe(onNext: { [weak self] (event) in 
      _ = try? self?.managedObjectContext.rx.update(event) 
     }) 
     .addDisposableTo(disposeBag) 

} 

func configureTableView() { 

    tableView.isEditing = true 

let animatedDataSource = RxTableViewSectionedAnimatedDataSource<AnimatableSectionModel<String, Event>>() 

animatedDataSource.configureCell = { dateSource, tableView, indexPath, event in 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 
    cell.textLabel?.text = "\(event.date)" 
    print("\(event.date)") 
    return cell 
} 

managedObjectContext.rx.entities(Event.self, sortDescriptors:[NSSortDescriptor(key: "date", ascending: false)]) 
     .map { events in 

[AnimatableSectionModel(model: "Section 1", items: events)] 

} 
.bindTo(tableView.rx.items(dataSource: animatedDataSource)) 
.addDisposableTo(disposeBag) 
    } 
} 

如何更新時,在界面

事件(ID更新UI: 「1」,日期:DATE( timeIntervalSince1970:0))

變成事件(ID: 「1」,日期:日期(timeIntervalSince1970:1))

回答