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 09-22-2011, 12:42 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 16
vksmaini is on a distinguished road
Question how to get selected cells data into an array?

Hello I have a tableView which is populating from an array(tableData). there are buttons on each cell. I wanted to know how to get particular data of cell into an array when i select that cell's button and similarly how i remove it when i again select that button on cell from array? this is what iam doing till now.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *CellIdentifier = @"Cell";
	
	CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
		cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		
	}

		// Set up the cell...
		// Configure the cell.
	if (tableView.tag == 1) {
		cell.textLabel.text = [unitArry objectAtIndex:indexPath.row];
	}
	else {
	
		
		UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"g1.png"]];
		[cell setBackgroundView:img];
		[img release];
	
		cell.productLbl.text= [NSString stringWithFormat:@"%@",[[tableData objectAtIndex:indexPath.row]objectForKey:@"nameOfVegetables"] ];		
		cell.bPriceLbl.text = [NSString stringWithFormat:@"Rs %d/Kg",
											[[[tableData objectAtIndex:indexPath.row] objectForKey:@"priceOfVegetables"] intValue]]; 
	
		cell.qtyLbl.text = [NSString stringWithFormat:@"QTY: %@ %@",[[tableData objectAtIndex:indexPath.row] 
																   objectForKey:@"quantityOfVegetables"],[[tableData objectAtIndex:indexPath.row] objectForKey:@"unitOfVegetables"]] ;
		
		cell.tPriceLbl.text = [NSString stringWithFormat:@"TOTAL: %@",[[tableData objectAtIndex:indexPath.row]
																		objectForKey:@"totalPriceOfVegetables"]];
		

		BOOL selected;
		if(selected){
			
			cell.unchecked.tag=indexPath.row;
			[cell.unchecked addTarget:self action:@selector(buttonMethod:) forControlEvents:UIControlEventTouchUpInside];

		}
		//else {
//			
//			cell.unchecked.tag=indexPath.row;
//			[cell.unchecked addTarget:self action:@selector(buttonRemoveMethod:) forControlEvents:UIControlEventTouchUpInside];
//		}


		
	}
	return cell;

		
}
-(void)buttonMethod:(id)sender{

	UIButton *button =  (UIButton *)sender;
	row = button.tag;
	NSNumber *yWrapped = [NSNumber numberWithInt:row];
	
	[btnArry addObject:yWrapped];
	NSLog(@"addObjectInbtnArry:%@",btnArry);

}
-(void)buttonRemoveMethod:(id)sender{
    //????
}
//here i wanted to add all cells index to an array and fetch the data from my tableData
- (void)buy:(id)sender
{
	

	[tmpArry addObjectsFromArray:btnArry];
	

	for (id obj in btnArry) {
	
		[tableData objectAtIndex:[obj intValue]];
	}
}
plz suggest me also how to remove the particular cell index from the same array when i click on the same button again of cell.
vksmaini is offline   Reply With Quote
Old 09-22-2011, 08:56 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

It doesnt look like you need a buttonRemovedMethod. Instead, in your buttonMethod, add a check before you do the addObject:. Check if the array contains another NSNumber just like the one you are about to add. If it does, then remove it. Otherwise, add it.

One big assumption here is that all of your button tags are unique.
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsindexpath, nsmutablearray, uitableview cell

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: 395
14 members and 381 guests
7twenty7, eski, EvilElf, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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