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 05-10-2010, 03:44 PM   #1 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default UITableView Select All

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…

Last edited by gtyt38; 05-11-2010 at 02:39 PM.
gtyt38 is offline   Reply With Quote
Old 05-13-2010, 02:01 AM   #2 (permalink)
Registered Member
 
kerofrog's Avatar
 
Join Date: May 2010
Posts: 63
kerofrog is on a distinguished road
Default

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.
kerofrog is offline   Reply With Quote
Old 05-13-2010, 02:30 PM   #3 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default

Quote:
Originally Posted by kerofrog View Post
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…
gtyt38 is offline   Reply With Quote
Old 05-14-2010, 02:18 AM   #4 (permalink)
Registered Member
 
kerofrog's Avatar
 
Join Date: May 2010
Posts: 63
kerofrog is on a distinguished road
Default

Quote:
Originally Posted by gtyt38 View Post
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;
}
kerofrog is offline   Reply With Quote
Old 05-14-2010, 02:44 PM   #5 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default

Quote:
Originally Posted by kerofrog View Post
: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…
gtyt38 is offline   Reply With Quote
Old 05-14-2010, 02:50 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

If you read the iPhone Human Interface Guidelines: Table Views, Text Views, and Web Views, you'll see that you should be using a checkbox anyway, and not a selection.

The Table View Programming Guide for iPhone OS: Managing Selections explains how to use the checkboxes.
JasonR is offline   Reply With Quote
Old 05-14-2010, 02:57 PM   #7 (permalink)
gtyt38
 
Join Date: Apr 2010
Location: Baltimore, MD, USA
Posts: 61
gtyt38 is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
If you read the iPhone Human Interface Guidelines: Table Views, Text Views, and Web Views, you'll see that you should be using a checkbox anyway, and not a selection.

The Table View Programming Guide for iPhone OS: Managing Selections explains how to use the checkboxes.
Here is part of my - (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath { method:
Code:
if ([self.toBeEmailed containsObject:[rowData objectForKey:@"Email"]]){
		[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
	}
	else
	{
		[cell setAccessoryType:UITableViewCellAccessoryNone];
	}
and my - (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath { method:
Code:
if ([self.toBeEmailed containsObject:[rowData objectForKey:@"Email"]]){
		[self.toBeEmailed removeObjectAtIndex:[self.toBeEmailed indexOfObject:[rowData objectForKey:@"Email"]]];
	}
	else
	{
		[self.toBeEmailed addObject:[rowData objectForKey:@"Email"]];
	}
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…

Last edited by gtyt38; 05-14-2010 at 05:44 PM.
gtyt38 is offline   Reply With Quote
Reply

Bookmarks

Tags
email, nsarray, nsdictionary, select all, uitableview

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: 318
14 members and 304 guests
Abidullah, baja_yu, cgokey, Duncan C, Fstuff, gbenna, guusleijsten, jbro, mdpauley, n00b, newDev, Sami Gh, seokwon lee, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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