Hi, I am working on an email app for a small organization. I am displaying people's names in a UITableView with an NSArray populated with individual NSDictionary's, containing that person's name, email address, etc... What I would like to know is how to make it so that when a user clicks a UIBarButtonItem on a toolbar, all of the table's contents are selected, and when all of the contents are selected, how to change the button to make it deselect all. Any help would be greatly appreciated!
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…
When the user click on your UIBarButtonItem, save the changed state in a variable then reload your tableview by calling
[tableview reloadData].
In your cellForRowAtIndexPath method:
Code:
if (userSelectedAll == TRUE) {
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
} else if (userSelectedAll == FALSE) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
Well, something along those lines should work .
Cliff.
Thank you for your help! But how would I declare the NSIndexPath? I've tried NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0]; and that doesn't seem to work…
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…
Thank you for your help! But how would I declare the NSIndexPath? I've tried NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0]; and that doesn't seem to work…
. No need to create an index path, it is passed to the method itself. You just need to call it.
Code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if (userSelectedAll == TRUE) {
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
} else if (userSelectedAll == FALSE) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
return cell;
}
:D. No need to create an index path, it is passed to the method itself. You just need to call it.
Code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if (userSelectedAll == TRUE) {
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
} else if (userSelectedAll == FALSE) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
return cell;
}
How do I do that if my action is in an IBAction and not in the - (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath method?
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…
where email is my source NSArray and toBeEmailed is the NSMutableArray I am using to store the selected items. So I am displaying checkmarks, its's just that I need help with checking and storing all of the cells in my NSMutableArray.
__________________
No animals were injured in the creation of this post…however, a few electrons were mildly inconvenienced…