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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 06-30-2010, 10:58 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 9
j0egas is on a distinguished road
Default Disable swipe to delete on tableview

Hi, I want to make it so when the user swipes on a cell, the delete button does not show up, but there is an edit button, and when you press that the tableview goes into editing mode, where the user can then delete the cells. I have been doing a lot of research on this, and can't seem to find the problem. Any suggestions? thanks!
j0egas is offline   Reply With Quote
Old 06-30-2010, 11:11 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

UITableView disable swipe to delete, but still have delete in Edit mode? - Stack Overflow
harrytheshark is offline   Reply With Quote
Old 06-30-2010, 11:16 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 9
j0egas is on a distinguished road
Default

I have tried that, and it doesn't seem to be working.
j0egas is offline   Reply With Quote
Old 06-30-2010, 11:26 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Works fine on my end, just make sure to change this line:
Code:
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Detemine if it's in editing mode
    if (self.tableView.editing) {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}
You can also use this:
Code:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
	return tableView.editing;
}
I've attached a quick example.
Attached Files
File Type: zip NoSwipe.zip (16.7 KB, 44 views)

Last edited by harrytheshark; 06-30-2010 at 11:33 AM. Reason: Added sample project
harrytheshark is offline   Reply With Quote
Old 06-30-2010, 12:39 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 9
j0egas is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
Works fine on my end, just make sure to change this line:
Code:
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Detemine if it's in editing mode
    if (self.tableView.editing) {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}
You can also use this:
Code:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
	return tableView.editing;
}
I've attached a quick example.
Thanks a lot man! The bool method worked!
j0egas is offline   Reply With Quote
Old 11-20-2010, 04:55 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 4
jwooten37830 is on a distinguished road
Default Sorry but no cigar.

Working on the iPad, i have tried implementing all these suggestions for keeping the Delete icon from rolling on to the end of the row when a swipe is done and I DON'T want to remove the row.

I have set a flag and in the canEditRowAtIndexPath method I return YES or NO depending upon the flag.

In the accessoryTypeForRowWithIndexPath i put the code to check on whether the table is editable and change the style as directed.

Delete always comes in when swipe to the left.

Neither of these methods get call BTW. But, the tableView:cellForRowAtIndexPath: gets called for sure.

What is going on?
jwooten37830 is offline   Reply With Quote
Reply

Bookmarks

Tags
button, delete, edit, remove, tablview

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
» Online Users: 328
7 members and 321 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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