bigfish24 / ABFRealmSearchViewController

Drop-in text search interface for Realm data
MIT License
87 stars 19 forks source link

RealmSearchViewController Only Shows First Record #1

Closed chodges closed 8 years ago

chodges commented 8 years ago

I have an interesting problem. Just implemented code using the RealmSearchViewController (swift). And what I'm finding is that the view controller only shows the first object in the data model. But when I select the search control and then press cancel all of the records will appear. So I don't have to actually search for anything --- just selecting it so it has the focus and then pressing cancel will do this.

Any idea why this might be happening? Here is the model that I'm using for the search:

import Foundation
import RealmSwift

class Contact: Object {

dynamic var id: Int = 0
dynamic var company: Company?
dynamic var lastname: String? = nil
dynamic var firstname = ""
dynamic var title: String? = nil
dynamic var email: String? = nil
dynamic var website: String? = nil
dynamic var notes: String? = nil
dynamic var picture: String? = nil
dynamic var acceptsPostcards: Bool = false
dynamic var attendsShowcases: Bool = false
dynamic var type: Int = 0
dynamic var metdate: NSDate? = nil
dynamic var favorite: Bool = false
dynamic var source: Int = -1
dynamic var source_id: Int = -1
dynamic var status = "N"
dynamic var external_id: Int = -1

let history = List<ContactHistory>()
let addresses = List<ContactAddress>()

override static func primaryKey() -> String? {
    return "id"
}

func getNextKey() -> Int{

    let realm = try! Realm()
    let contact_id : Int? = realm.objects(Contact).max("id")

    if(contact_id == nil){
        return 1
    }else{
        return contact_id! + 1
    }

}

}

And In the storyboard I've entered "Contact" for the Entity Name, "lastname" as the Search Property, Sort Ascending is ON. Nothing out of the ordinary there.

chodges commented 8 years ago

Sorry figured out what it was. I had forgotten to use these:

self.tableView.estimatedRowHeight = 50
self.tableView.rowHeight = UITableViewAutomaticDimension
bigfish24 commented 8 years ago

Sorry didn't get to the this sooner but glad you figured it out.

chodges commented 8 years ago

Thanks for that. But I am still having a problem. How do I force a reload of the data. Tried using self.tableView.reloadData() but its not working as expected. Let me explain:

1) I'm loading a form view for data entry. Actually I'm presenting modally the form view to add another Contact. 2) When the form dismisses itself and control is handed back to the calling controller (in this case the RealmSearchViewController) the controller isn't automatically re-reading the records and showing the new row in the table

Again the only way for me to see the new record in this case is yup you guessed it: Selecting the search bar so it has the focus and then pressing cancel.

Wondering if there's a func that I'm missing that forces a re-read of the data.

Thanks.

bigfish24 commented 8 years ago

@chodges this needs to be added, I will do so now. Thanks for the feedback!

chodges commented 8 years ago

Awesome. Thanks so much for adding this!