In my app I need to delete multiple rows in a table, edit the table and get a check box beside the table. When checked then the table cells are deleted. It is like the iPhone message app. How can I do this, please help me.
Buka dokumen PDF yang akan diedit dan klik kanan. Klik Open With lalu pilih Adobe Acrobat. Klik Tools dan pilih opsi Edit PDF. Silahkan gunakan toolbar yang ada untuk melakukan edit PDF.
Klik dua kali kata Text. Setelah itu, Anda bisa memasukkan atau mengetikkan teks. Tikkan tulisan yang Anda ingin tambahkan ke dokumen PDF. Tambahkan tanda tangan (opsional). Jika dokumen PDF memuat formulir yang perlu ditandatangani, Anda juga bisa menggunakan Preview untuk menambahkan tanda tangan sendiri.
If I understand your question correctly, you essentially want to mark UITableViewCell
s in some way (a checkmark); then, when the user taps a master "Delete" button, all marked UITableViewCell
s are deleted from the UITableView
along with their corresponding data source objects.
To implement the checkmark portion, you might consider toggling between UITableViewCellAccessoryCheckmark
and UITableViewCellAccessoryNone
for the UITableViewCell
's accessory
property. Handle touches in the following UITableViewController
delegate method:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];
if (c.accessoryType == UITableViewCellAccessoryCheckmark) {
[c setAccessoryType:UITableViewCellAccessoryNone];
}
//else do the opposite
}
You might also look at this post regarding custom UITableViewCell
s if you're wanting a more complex checkmark.
You can set up a master "Delete" button two ways:
In either case, eventually a method must be called when the master "Delete" button is pressed. That method just needs to loop through the UITableViewCells
in the UITableView
and determined which ones are marked. If marked, delete them. Assuming just one section:
NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init];
for (int i = 0; i < [tableView numberOfRowsInSection:0]; i++) {
NSIndexPath *p = [NSIndexPath indexPathWithIndex:i];
if ([[tableView cellForRowAtIndexPath:p] accessoryType] ==
UITableViewCellAccessoryCheckmark) {
[cellIndicesToBeDeleted addObject:p];
/*
perform deletion on data source
object here with i as the index
for whatever array-like structure
you're using to house the data
objects behind your UITableViewCells
*/
}
}
[tableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted
withRowAnimation:UITableViewRowAnimationLeft];
[cellIndicesToBeDeleted release];
Assuming by "edit" you mean "delete a single UITableViewCell
" or "move a single UITableViewCell
," you can implement the following methods in the UITableViewController
:
- (void)viewDidLoad {
[super viewDidLoad];
// This line gives you the Edit button that automatically comes with a UITableView
// You'll need to make sure you are showing the UINavigationBar for this button to appear
// Of course, you could use other buttons/@selectors to handle this too
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//perform similar delete action as above but for one cell
}
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
//handle movement of UITableViewCells here
//UITableView cells don't just swap places; one moves directly to an index, others shift by 1 position.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With