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 12-15-2010, 12:40 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default How to check cell is selected for UITbaleview

I have UITableViewController.when i tap a cell i need to display check mark in left side of selected cell for indication of cell is selected.How to check the cell selection .

Last edited by rk_mail04; 12-15-2010 at 02:31 PM.
rk_mail04 is offline   Reply With Quote
Old 12-15-2010, 12:57 PM   #2 (permalink)
WSD
Registered Member
 
Join Date: Jul 2009
Location: Canada
Posts: 38
WSD is on a distinguished road
Default try this

in didSelectRowAtIndexPath: method, add:
Code:
 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
			 [cell setSelected:YES animated:YES];
			 [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
WSD is offline   Reply With Quote
Old 12-15-2010, 02:30 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

Quote:
Originally Posted by WSD View Post
in didSelectRowAtIndexPath: method, add:
Code:
 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
			 [cell setSelected:YES animated:YES];
			 [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
I have 4 rows. after selecting first cell its ok. when i select second cell i need to disable first cell check mark and show check mark in second is selected .This is up to 4th cell. but check mark should be left side.

Last edited by rk_mail04; 12-15-2010 at 02:36 PM.
rk_mail04 is offline   Reply With Quote
Old 12-17-2010, 09:33 AM   #4 (permalink)
WSD
Registered Member
 
Join Date: Jul 2009
Location: Canada
Posts: 38
WSD is on a distinguished road
Default You have to uncheck the previously selected row first

Add a loop that unchecks ALL rows, then put a checkmark in currently selected row.
Add something like this to didSelectRowAtIndexPath: method:
Code:
for(int iterator=0;iterator<aData.count;iterator++){
			 
			 UITableViewCell *eachCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:iterator inSection:0]];
			 [eachCell setSelected:NO animated:YES];
			 [eachCell setAccessoryType:UITableViewCellAccessoryNone];
			 }
			 
			 UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
			 [newCell setSelected:YES animated:YES];
			 [newCell setAccessoryType:UITableViewCellAccessoryCheckmark];
From what I know, checkmark is always on the right. If you want it on the left, you'll have to use a custom image...

Last edited by WSD; 12-17-2010 at 09:37 AM.
WSD is offline   Reply With Quote
Old 12-18-2010, 02:31 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

Its working fine for your sample . I am also tried for custom in left side checkmark its fine .

Code:
- (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];
		[[cell imageView] setImage:[UIImage imageNamed:@"Tick.png"]];

    }
    [[cell imageView] setHidden:YES];
	
	if (indexPath.row == selectedRow) 
	{
		
		[[cell imageView] setHidden:NO];
	}
	
    // Set up the cell...
	NSString *cellValue =[listOfItems_CervicalFluid_Input objectAtIndex:indexPath.row];
	cell.text = cellValue;
	return cell;
}
didSelectRowAtIndexPath method 

selectedRow = indexPath.row;
	[self.tableView reloadData];

In header file
 int selectedRow=-1 // init

Quote:
Originally Posted by WSD View Post
Add a loop that unchecks ALL rows, then put a checkmark in currently selected row.
Add something like this to didSelectRowAtIndexPath: method:
Code:
for(int iterator=0;iterator<aData.count;iterator++){
			 
			 UITableViewCell *eachCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:iterator inSection:0]];
			 [eachCell setSelected:NO animated:YES];
			 [eachCell setAccessoryType:UITableViewCellAccessoryNone];
			 }
			 
			 UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
			 [newCell setSelected:YES animated:YES];
			 [newCell setAccessoryType:UITableViewCellAccessoryCheckmark];
From what I know, checkmark is always on the right. If you want it on the left, you'll have to use a custom image...

Last edited by rk_mail04; 12-18-2010 at 02:33 AM.
rk_mail04 is offline   Reply With Quote
Old 12-18-2010, 02:37 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

Its working fine for your sample . I am also tried for custom in left side checkmark its fine .
Now i have one more question about same uitableview cell selection. after selecting my cell i am indication in check mark cell is selected. When its going back to main uiviewcontroller and coming back to check there is no selection cell check mark. what happening now . beuase i am already selected my cell.

Code:
- (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];
		[[cell imageView] setImage:[UIImage imageNamed:@"Tick.png"]];

    }
    [[cell imageView] setHidden:YES];
	
	if (indexPath.row == selectedRow) 
	{
		
		[[cell imageView] setHidden:NO];
	}
	
    // Set up the cell...
	NSString *cellValue =[listOfItems_CervicalFluid_Input objectAtIndex:indexPath.row];
	cell.text = cellValue;
	return cell;
}
didSelectRowAtIndexPath method 

selectedRow = indexPath.row;
	[self.tableView reloadData];

In header file
 int selectedRow=-1 // init
[/quote]
rk_mail04 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, uitableview, xcode

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: 397
9 members and 388 guests
chemistry, daudrizek, HemiMG, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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