Display dynamic data in scrollable tableview in Cocos2d - ios

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.

Related

UITableView reloadRows only works every other time

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!

Matching a user to a message using Swift and Parse

I'm currently writing a social networking app for iOS using Swift and the Parse SDK. My app is basically a UITableView that displays a timeline of messages from users that sign up for my app. But there is one part that I'm struggling with that I hope the community will be able to help me solve.
My problem is that I want a user to able to tap on a message in my tableview and display the contents of the message and the user that sent it in a UILabel. I pretty much have tried everything I could think of to create this logic but I seem to make things worse. I'm pretty sure a PFquery needs to be used somewhere in this logic. I will attach my source code for my TimelineTableViewController and my custom tableview cell. Full code examples on how to achieve this logic in Swift will be very helpful since I'm already behind.
Thanks in advance
Derek Cacciotti
Twitter: #derekcacciotti
TimelineTableViewController
TableViewCell
In didSelectRowAtIndexPath, use the indexPath to help you figure out which message was tapped like so:
let message: PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
From there, get the values of your message by key (or create a Message class that is a proper PFObject subclass), then use those values to construct a string for your label.

Retrieve text from array

I am working on an app where I send a query to a webpage and get the information and save it into my array. Now, all this works except for then I come to take the value from my array and display it in my text view. using this code
-(void)viewDidAppear:(BOOL)animated
{
self.tvSoilN.text = [[_soilNotes objectAtIndex:0] objectForKey:#"crop"];
}
However, I get the error of the array being empty.
Now that makes sense because using a breakpoint I can see that the code above actually runs before the code be in my model.m file which I use to write the data in the array
I cant post images but when I use a break point on the if(self.delegate) line It shows me
_locations (and when i drill down i see)
_crop_soil(this is the field in my database)=#"Blah blah blah")
which makes me realize that my data is indeed being retreived from online. But i am just having difficulty in displaying it from my array or anywhere.
Would like some help in especially where to call my array as I also think i am doing it wrong.Thanks you
IN Implementation file
-(void)itemsDownloaded:(NSArray *)items
{
// This delegate method will get called when the items are finished downloading
// Set the downloaded items to the array
_soilN = items;
NSLog(#"soil%#",_soilNotes);
self.tvSoilN.text=[[_soil objectAtIndex:0]objectForKey:#"crop"];
}
Use valueForKey not objectForKey. Got there in the end!

Parse, How to send array entries as multiple PFObjects, Create a new row for each array object

I'm using Parse as the backend for my app. My app will be used in the field where service will nonexistent or spotty at best so I need to store information offline. I currently save data for the user in a plist in the background (Title, location coordinates, notes, additional data). Since Parse's current iOS offline saving is fairly poor (From what I've read), I was hoping to get around it by creating an array or dictionary from the plist and upload that to Parse by giving it an array once the user is back in cell range.
As it occurs now, when I upload the array, it simply puts the entire contents of the array in a single cell in the database. Is there a way to parse the array and create a new row for each entry/object in the array?
I may have overlooked a better way to do this. If someone has a suggestion I would appreciate it!
I solved it. I iterated through the array using a for loop and added each index as a separate object.

CoreData fault - how to get data

I've researched tons of questions and documents about CoreData returning faults instead of actual values:
Relationship 'whiskers' fault on managed object (0xb7abab0)
This happens when I'm trying to get the count for the number of whiskers, such as:
self.numWhiskersLabel.text = [NSString stringWithFormat:#"%d", cat.whiskers.count];
Even if I try to log the whiskers set directly I still get a fault:
NSLog(#"whiskers: %#", cat.whiskers);
I understand that "Core data will not return full object until there is a need to access the actual value of that object. Each of your returned objects will be a 'fault' until this point." That's great, but there is a need to access the actual value at this point. I need the value right now! So how do I get out of this oxymoron? How can accessing the count of a Set not be considered needing the value?
I didn't get any feedback from my comment so I'm just going to assume whiskers is a set of NSManagedObjects
The set wont be loaded initially because internally it's coming from another table in the db. When you access .whiskers.count it still doesn't need to go and get the data yet, because all you're wanting is the number of whiskers in the set.
When you pull a whisker out of the set, then it will be faulted, try doing
NSLog(#"whiskers: %#", [cat.whiskers.anyObject anyProperty]);
That should give you a loaded NSManagedObject.
This is an error condition. Something is wrong with that NSManagedObject instance. Either it was deleted before you accessed it or you are trying to touch it from the wrong thread.
Please edit your question and show the code that is accessing that NSManagedObject.
Also, what happens when, in the debugger, you just do a po cat? Do you see the full Cat object or is that giving a fault error as well?

Resources