Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-23-2009, 09:28 PM   #1 (permalink)
New Member
 
Join Date: May 2009
Posts: 4
Default TableView Question

I am trying to allow the user of my software to empty out an array/UITableview (delete all items in the array and update the tableview that displays the array at the same time). I have managed to empty the array (actually a mutable array) with this:
Quote:
[self.listData removeAllObjects];
I know it properly removes everything, because the array gets saved to a propertylist/file when the application closes, and upon reloading I can see the data was in fact deleted. However, the application crashes (sooner or later - doesn't always happen right away) if I try to scroll the tableview after emptying it, and I'm sure this is because I am not updating the tableview properly after emptying the array. I think I need to use a line like this:
Quote:
[tableView deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animatio n];
to update the tableview, but I really don't understand how to use this method. I think I understand what an indexPath is, but how do I set up an array of them to make sure all data is deleted?
Mick is offline   Reply With Quote
Old 05-23-2009, 11:56 PM   #2 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by Mick View Post
I am trying to allow the user of my software to empty out an array/UITableview (delete all items in the array and update the tableview that displays the array at the same time). I have managed to empty the array (actually a mutable array) with this:


I know it properly removes everything, because the array gets saved to a propertylist/file when the application closes, and upon reloading I can see the data was in fact deleted. However, the application crashes (sooner or later - doesn't always happen right away) if I try to scroll the tableview after emptying it, and I'm sure this is because I am not updating the tableview properly after emptying the array. I think I need to use a line like this:


to update the tableview, but I really don't understand how to use this method. I think I understand what an indexPath is, but how do I set up an array of them to make sure all data is deleted?
That is most likely not your problem.

If you remove the contents of the array you use as data source you would probably call [myTableView reloadData]. This causes the table view to ask for how many rows there are now (0). So it will just draw a blank table.

The method you mention is good for animating the removal of single rows. So the pattern usually is: remove from NSArray, then make the table animate the removal.

I suspect your problem is that you are accessing memory that was previously released.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 05-24-2009, 01:26 PM   #3 (permalink)
New Member
 
Join Date: May 2009
Posts: 4
Default

Thank you very much. I think my only remaining question is what to put for "myTableView" - I take it that is supposed to stand for the UItableview I am using - but I'm not sure what to call it in my software. Everything I try gives me an "undeclared" error (ie, if I use myTableView or just tableView, I get that error. I also tried self.tableView and that gave me an error saying there was no such structure).

Could the problem be that I did not declare an outlet for the tableview? I'm not sure if that is necessary or not. If that is not the problem, how do I figure out what to put for "myTableView"?

Maybe I should point out - I have been programming for a long time but I am very new to iPhone / objective C programming. I have been following a bunch of UITableView tutorials online, but I've had trouble making them work properly, at least in part because OS 2.2 seems to treat tableviews a little differently - or maybe just more strictly. Also, some tutorials start with projects based on the View-based template, some start with projects based on the Navigation-based template, and it's possible I have mixed and matched them improperly. In other words, perhaps there is something I left out that would have been generated automatically had I used the proper template.

Anyway, thanks again for your continued help!

Quote:
Originally Posted by Oliver Drobnik View Post
That is most likely not your problem.

If you remove the contents of the array you use as data source you would probably call [myTableView reloadData]. This causes the table view to ask for how many rows there are now (0). So it will just draw a blank table.

The method you mention is good for animating the removal of single rows. So the pattern usually is: remove from NSArray, then make the table animate the removal.

I suspect your problem is that you are accessing memory that was previously released.
Mick is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,475
Threads: 89,090
Posts: 380,122
Top Poster: BrianSlick (7,091)
Welcome to our newest member, drg4cen
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0