Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
TableView duplicating and overwriting previous data?
I have a textView and a tableView. I'm just testing something at the moment to ensure I can execute my idea.
It's pretty simple, here's how it works. User types text into textview and when clicking the close button of the textView the text is added to the tableView.
I've got that working but every time I add some more text to the textView and click the close button, the previous stuff gets overwritten in the tableView and a duplicate record shows...can someone advise what I might be doing wrong...thanks.
This is the code I'm using to get the string into the table:
I suspect this code works, but it doesn't make sense to be returning something in a void method. Although I'm not sure why you care about the column in this method but you don't in the other one.
I'd suggest just commenting out this method altogether until you get the immediate issue sorted out.
Okay so I'm making some progress with this albeit incredibly slowly...can't believe this is causing such a headache!!
Basically I changed the NSTextView to an NSTextField and it resolves the duplicate issue! Doesn't help much as I still don't know why it's happening but at least something has changed!
So now the code looks like this when adding to the table:
Bear with the method change title as I created a new project to see if that resolved the issue so am currently working with the new project at present. As you can see I was using:
I'll bet it works. If so, I'll explain what I think is happening.
THANK YOU BRIAN :D
Finally it's working. Now I'm going to hazard a guess at what I think the problem was! Because I wasn't copying the TextField data but rather storing the first piece of data available it constantly had that in memory and so was overwriting all the other data and therefore duplicating?
Right idea, I guess. NSTextStorage is a subclass of NSMutableAttributedString, mutable being the important part. I do not see any indication that any of the methods you were using created a copy of the object. So when you added the string to your dictionary again, it was actually the same instance. Thus, there was only one string object, not two, so changing one caused a change in both places. By making a copy, you break that cycle.
I might have been bitten by this myself, but I'm typically shoving strings into copy properties. I don't think the text storage part is strictly necessary, as I have been pulling stuff out using [textView string], but again it does not appear to copy the value.
Replies
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeFor example user types this in the textView:
"Test 1"
The button is clicked and "Test 1" pops up in the first table cell...groovy!!
The user then types this in the textView:
"Test 2"
The button is clicked and 'Test 2" appears in the first table cell (over writing Test 1) and also appears in the 2nd table cell....Not so groovy!!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeOnce the close button is clicked, this code fires:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI suspect this code works, but it doesn't make sense to be returning something in a void method. Although I'm not sure why you care about the column in this method but you don't in the other one.
I'd suggest just commenting out this method altogether until you get the immediate issue sorted out.
I'm not seeing the issue yet.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeBasically I changed the NSTextView to an NSTextField and it resolves the duplicate issue! Doesn't help much as I still don't know why it's happening but at least something has changed!
So now the code looks like this when adding to the table:
Bear with the method change title as I created a new project to see if that resolved the issue so am currently working with the new project at present. As you can see I was using:
to get the TextView value but am now using:
To get the TextField value. Maybe this has something to do with it? Clutching at straws I know!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeGo back to what you had before, but make this change:
I'll bet it works. If so, I'll explain what I think is happening.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeFinally it's working. Now I'm going to hazard a guess at what I think the problem was! Because I wasn't copying the TextField data but rather storing the first piece of data available it constantly had that in memory and so was overwriting all the other data and therefore duplicating?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI might have been bitten by this myself, but I'm typically shoving strings into copy properties. I don't think the text storage part is strictly necessary, as I have been pulling stuff out using [textView string], but again it does not appear to copy the value.
Watch out for a leak if you are not using ARC.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou're absolutely right about the textStorage part, there's no need so I have removed it.
Now onto saving the data using CoreData...could be fun! :rolleyes:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome