I have a custom UITableView ('table') fed by a data array (e.g. 'rowVals[]') which does not display correct values after making a data change.
Error Case
Init table to 5 rows with values fed by 'rowVals' = ["R1" - "R5"]
post - displays correctly
Change rowVals[1] from "R2" to "S2"
post - shows init values (e.g. w/"R2")
Call table.reloadRows() on the table
post - shows new values (e.g. w/"S2")
(BUG!) Call table.reloadRows() on the table
post - shows init values again! (e.g. w/"R2")
Steps #3/#4 now cycle repeatedly!
Question
Why is this occurring, where is the table finding "R2" to display? I have spent over two hours debugging this to no avail, yikes! Thoughts?
Thank you for the suggestion Paulw11, with debugging and persistence I was able to resolve and correct this.
Problem Source
Custom cells, initialized on viewDidLoad() in vc
Problem Solution
Have tableView(cellForRowAtIndexPath) return the cell directly, not by dequeueReusableCell()
I am not sure entirely why this corrected to problem but it does somewhat make sense, dequeueReusableCell() returns a new cell when the 'identifier' is not found!
Related
I'm attempting to have my individual UITableViewCells: I'd love to have the initial values of the model brought over to their UI representation as well as after the user makes a change have the new UI value brought back to the model. Let's just focus on the latter first: UI changes propagating to the model.
For a little more background understanding, I'm running into an issue when adding a new item. This table is driven by an NSFetchedResultsController which sends one didChangeObject with a ChangeInsert and a second didChangeObject for ChangeUpdate. The ChangeInsert triggers an insertRowsAtIndexPaths on the table and the ChangeUpdate does a reloadRowsAtIndexPath.
Because of these two responses my table view asks for cellForRowAtIndexPath twice. This shouldn't be a problem if the same cell is disposed of properly between requests but it doesn't appear to be: I receive an assert that the property in the model is already bound to a RACSignal! I've tried any number of ways to be more explicit such as:
RAC(self.model,value) = [ [RACSignal merge:#[self.valueField.rac_textSignal] ] takeUntil:self.rac_prepareForReuseSignal]
however the reuse signal does not fire in time as it still asserts (aside, is there a recommended way to directly debug a signal like this firing?)
I've tried adding an additional takeUntil:[RACObserve(self, model) to dispose of the signal as soon as the reused cell's model is overwritten (and have it bind to the new model) and understandably this seems to result in the first value disposing. However adding skip:1 to the observe puts me right back where I am.
Please let me know if there is anywhere else I can add clarity or if you have another way to lay these things out. I'm very new to Reactive Cocoa and still learning best practices :)
Thanks!
I am trying to add records dynamically to an already populated UITable. In my UITableView class I have a custom List object
List<CustomObject> _data=new List<CustomObject>();
where I add records to from my webservice call like so:
_data.Add(Json(Object));// Json returns a list of CustomObject
//table is a UITableView
//this.table.InsertRows(_data);
I know this above line won't work because its expecting an NSIndexPath[] but I am not sure how to go about adding the new items an load only the new items added. I don't really follow objective C very well so examples I found don't help so much
Generally, you will add data to your List, and then call ReloadData() on your TableView. You usually only call InsertRows() if you want to insert data at a particular spot in the table based on some sort of user action.
You are trying to add a List of CusomObject as CusomObject to a List<CusomObject> ,that is not quite right.you should be adding a CusomObject to List<CusomObject>.
I am making an app in cocos2d. I am using SWTableView library for displaying dynamic contents in tableview in cocos2d. There is absolutely no problem when I am running sample code from SWTableView Example
But when I load my data from server which is dynamic the tableview crashes on scroll.
It allows me to scroll well in the static data just like in the example but I am not able to figure out error as it just gives me BAD_ACCESS.
Note: Possible reason i feel is dynamic data.
If any better method is there to load dynamic data in scrollable way in cocos2d then please suggest.
Thank u.
I just found the solution. There was very strange problem but all working now.
Basically in the sample code (i mentioned in my question) there is a delegate method called
-(SWTableViewCell *)table:(SWTableView *)table cellAtIndex:(NSUInteger)idx;
here idx is NSUInteger but whenever i directly used it without converting it to int or NSInteger it gave BAD_ACCESS command.
Then i stored my data in MutableDictionary and gave it key as its index string
i.e for name data of first person i gave key as "0" (string) and value as name.
Hence whenever i retrieved those values i used
[name objectForKey:[NSString stringWithFormat:#"%d", idx]]
which worked absolutely fine.
Also to mention here the other delegate called
-(NSUInteger)numberOfCellsInTableView:(SWTableView *)table;
returns an integer value, but when i used [Values count] my app used to crash on scroll.
Values is my main array where i store my data received from server.
Finally i started storing my data count in NSUserdefaults and my problem got solved.
Hope this helps somebody.
So let's see if I can write a clear enough description of my problem...
I'm developing an application for a museum, where the user can find artworks either through an id or by scanning a qr tag...
Once either an id is entered or a tag scanned, the application sends the user from the search view, to the info view.
The info view gathers information about the artwork from an SQLite database...
My problem is, that in the info view, I call the function from the database class as such:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *paintingInfo = [[PaintingDatabase database] findPaintingByID];
(additional code)
}
And I have no problem getting the info... works fine...
But my problem is, that if I go back to the search view and enter a new id or scan a new tag, the call/search isn't run again, since the view is still in memory...
So, how would I go about running
NSArray *paintingInfo = [[PaintingDatabase database] findPaintingByID];
every time I enter the view...?
I've tried placing it in viewDidAppear instead, but I get an EXC_BAD_ACCESS error...
I think you are close to answering your own question. Since viewDidLoad only gets called when your view loads, if you are using the same ViewController you will not get the results you are looking for. One option may be to destroy and create a new ViewController each time. This probably would be acceptable, performance-wise. Another option (that you seem to have explored) is to put your code in viewWillAppear. I would probably look into this more, and figure out what is causing your crash.
It's a bit difficult to tell from a brief description, but this feels to me like it's more of an application architecture issue than a problem with a specific bit of functionality.
You might be better off with an alternative approach, running the query from outside the info view, and then update the properties of the view through a delegate method. That's more of an MVC approach - the controller retrieves the data from the model, then passes the data over to the view to be displayed.
As you've described it, it seems like your info view is taking both view and controller functions - which could be why you're running into problems trying to get different data once the initial view is finished with.
The crash doesn't sound like a problem with the view, though - I'd second the advice to track that down and nail it as a separate issue.
I have quite a frustrating problem that I have been struggling with for quite some time.
To provide some context and detail I have an iOS UISplitViewController application - standard master / detail stuff. The master view is a UITableView backed with an NSFetchedResultsController (which loads NSManagedObjects from a SQLite data store).
What seems to be happening is that any update within the details view (which can routinely cause updates to the 'master records' and are flushed to NSManagedObject's and ultimately the SQL data store) causes a DELETE operation on the NSFetchedResultsController.
I assume that this is because the write to the NSManagedObject property(s) are causing a fault of some kind, which in turn causes the NSFetchedResultsController to expunge it from it's cached result set. The end result is that records go 'missing' from the master view (e.g.: UITableCellView's are removed from the master UITableView).
The issue is that I don't want this to happen and I have no idea how to stop it...
Has anyone experienced this issue before and could possibly provide some guidance?
Thanks in advance,
Ben
I'm not sure if this answers your question, but I figured out the solution to a similar problem I was having. I was sorting the objects in my Core Data-backed UITableView by the first letter of the name of each object. In whatever tutorial I read, it told me to put a transient property 'NameInitial' in the NSManagedObject subclass that I would populate with the first letter of the name of that object. I then used that property as my sectionNameKeyPath to sort the objects into the proper sections in my UITableView.
I had a button on each cell that updated a property of the object associated with that cell, and I properly received NSFetchedResultsChangeUpdate messages in my didChangeObject delegate function. HOWEVER, sometimes, cells would get deleted and I would receive the NSFetchedResultsChangeDelete message for no apparent reason.
Then I noticed that the cells that were getting deleted had (null) as the NameInitial property for their associated object. I had forgotten that the transient NameInitial is only stored in memory, and so is not necessarily maintained all the time. Once I manually repopulated the NameInitial property each time I updated a cell, the deleting stopped. So if you are using a transient property to help sort/section your UITableView, this might be your problem.
Hope this helps, and good luck!
-Rick