How to hide button when in edit mode in UITableViewCell - iphone

Can i hide my button inside cell when edit mode? My cell populate by array, save in plist. This is my code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [titleArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"the indexpath.row = %i",indexPath.row);
UITableViewCell *cell = [[UITableViewCell alloc]init];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(250.0, 25.0, 30.0, 30.0)];
[button setTitle:#"!" forState:UIControlStateNormal];
[button setTitle:#"X" forState:UIControlStateSelected];
[button setTag:indexPath.row + 100];
[button addTarget:self action:#selector(onoffBtn:) forControlEvents:UIControlEventTouchUpInside];
// my label code
UIImageView *bgCell = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , 320, 80)];
bgCell.image = [UIImage imageNamed:#"BG.jpeg"];
[cell.contentView addSubview:button];
// other cell contentView addSubview everything
return cell;
[tableView reloadData];
}
This is my edit button
- (IBAction)editBtn:(id)sender
{
UIButton *editBtn = (UIButton *)sender;
editBtn.selected = !editBtn.selected;
if (editBtn.selected)
{
button.hidden = YES;
[self.tableView setEditing:YES animated:YES];
}
else
{
button.hidden = NO;
[self.tableView setEditing:NO animated:YES];
}
}
with above code, my button hide in last cell only, just say if i have 3 cells. How do i hide all button hide when in edit mode? i want all button is hiding. Below is my onoffBtn.
- (IBAction)onoffBtn:(id)sender
{
tempIndexPath = [_tableView indexPathForCell:(UITableViewCell*)[[sender superview] superview]];
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:tempIndexPath];
UIButton *onoffBtn = (UIButton *)[cell.contentView viewWithTag:tempIndexPath.row+100];
onoffBtn.selected = !onoffBtn.selected;
if (onoffBtn.selected)
{
// start
}
else
{
// stop
}
}
Please teach me more. Thank you.

You will have to call this method for all the UiTableViewCells of the table:
if (editBtn.selected)
{
for (int row = 0, rowCount = [_iTableView numberOfRowsInSection:0]; row < rowCount; ++row) {
UITableViewCell *cell = [_iTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];
UIButton *onoffBtn = (UIButton *)[cell.contentView viewWithTag:tempIndexPath.row+100];
onoffBtn.hidden=YES;
}
}

Related

How to hide or show button on row selection?

I am new in iOS development, I have a custom table view on which have placed 3 buttons namely,
Add comment
Up arrow
Down arrow
I want to increase the height of cell when down arrow button is pressed, also make add comment button, downarrow button visible.
My code,
#import "JCoutGoingConfess.h"
#interface JCoutGoingConfess (private)
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath;
#end
#implementation JCoutGoingConfess
#define kCellHeight 132.0
#synthesize outConfessionNavbarBAckBtn,JCoutGoingTbl;
//---------------------------- TableView---------------------------------------
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
{
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:1 inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 2.0;
}
return kCellHeight;
}
- (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];
}
// ----------------------- cellbackground image-----------------------------
if([self cellIsSelected:indexPath]){
cell.backgroundView =[[UIImageView alloc]initWithFrame:CGRectMake(160, 151, 320, 108)];
cell.backgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"inCellFullBg.png"]];
}
// ******** imageView on cell *******
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(112,0, 90, 90)];
imgView.image = [UIImage imageNamed:#"friendsfacepic.png"];
[cell.contentView addSubview:imgView];
//----------------------------Cell buttons-------------------------------------------
if (JcOutCellSize==152)
{
UIButton *AddComment = [UIButton buttonWithType:UIButtonTypeCustom];
[AddComment addTarget:self
action:#selector(TestBtns:)
forControlEvents:UIControlEventTouchDown];
AddComment.frame = CGRectMake(9.0, 128.0, 96.0, 26.0);
[cell.contentView addSubview:AddComment];
UIImage *buttonAddComment = [UIImage imageNamed:#"addcomment.png"];
[AddComment setBackgroundImage:buttonAddComment forState:UIControlStateNormal];
[cell.contentView addSubview:AddComment];
UIButton *UpArrow = [UIButton buttonWithType:UIButtonTypeCustom];
[UpArrow addTarget:self
action:#selector(ResizeCell:)
forControlEvents:UIControlEventTouchDown];
//[DownArrow setTitle:#"Arrow" forState:UIControlStateNormal];
UpArrow.frame = CGRectMake(143.0, 136.0, 26.0, 16.0);
[cell.contentView addSubview:UpArrow];
UIImage *buttonUp = [UIImage imageNamed:#"upArrow.png"];
[UpArrow setBackgroundImage:buttonUp forState:UIControlStateNormal];
[cell.contentView addSubview:UpArrow];
}
//----------------------------------------------------------------------------------
if (JcOutCellSize==132)
{
NSLog(#" down arrow %f",JcOutCellSize);
UIButton *DownArrow = [UIButton buttonWithType:UIButtonTypeCustom];
[DownArrow addTarget:self
action:#selector(IncreseCellHight:)
forControlEvents:UIControlEventTouchDown];
DownArrow.frame = CGRectMake(143.0, 116.0, 26.0, 16.0);
[cell.contentView addSubview:DownArrow];
UIImage *buttondown = [UIImage imageNamed:#"upDownArrow.png"];
[DownArrow setBackgroundImage:buttondown forState:UIControlStateNormal];
[cell.contentView addSubview:DownArrow];
NSLog(#" cell size = %f",JcOutCellSize);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:indexPath];
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
[JCoutGoingTbl beginUpdates];
[JCoutGoingTbl endUpdates];
}
- (void)viewDidLoad
{
selectedIndexes = [[NSMutableDictionary alloc] init];
[super viewDidLoad];
}
- (void)viewDidUnload
{
selectedIndexes = nil;
[super viewDidUnload];
}
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
// Return whether the cell at the specified index path is selected or not
NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath];
return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
}
This is not working as expected, what could be the problem?
set any integer variable value in button action and put condition in heightForRowAtIndexPath, whatever size you want, and then reload table

Hide UIButton of UITableviewcell

I have one Simple critical Problem in my code .
On my Tableview when I pressed on my Edit button (which is on navigationbar) It takes me to edit method of UITableview . I want to hide button and label which is on My Cell .
Code :
I am adding my Button like this ..
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *currentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
currentCell = nil;
if (currentCell==nil)
{
currentCell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
BtnEmail=[UIButton buttonWithType:UIButtonTypeCustom];
//BtnEmail = (UIButton *)[currentCell viewWithTag: 3];
BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.tag=indexPath.row;
//[BtnEmail setTitle:#"E-mail" forState:UIControlStateNormal];
[BtnEmail setBackgroundImage:[UIImage imageNamed:#"email.png"] forState:UIControlStateNormal];
[BtnEmail addTarget:self action:#selector(BtnEmail:) forControlEvents:UIControlEventTouchUpInside];
[currentCell.contentView addSubview:BtnEmail];
[currentCell.contentView bringSubviewToFront:BtnEmail];
return currentCell;
}
My Edit button is Declare like this
Edit Button :
self.navigationItem.rightBarButtonItem = self.editButtonItem;
And On edit click My this method will call .
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[listTableView setEditing:editing animated:animated];
if(editing)
{
self.navigationItem.leftBarButtonItem.enabled = NO;
//BtnEmail.frame=CGRectMake(355, 17, 25, 25);
BtnEmail.hidden = TRUE;
}
else
{
self.navigationItem.leftBarButtonItem.enabled = YES;
//BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.hidden = FALSE;
}
[super setEditing:editing animated:animated];
}
In this case my Last cell Button and Lable gonna hide not all . I need to hide all the UIButton of my Cell .
Like if I have 3 cell on table then it will hide only last button only ..
Thanks .
You can do it simply making a conditional check in cellForRow and reload the table view when the editing changed.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do your other stuff
// Add this conditional check
if (tableView.editing)
{
BtnEmail.hidden = YES;
}
else
{
BtnEmail.hidden = NO;
}
[currentCell.contentView addSubview:BtnEmail];
[currentCell.contentView bringSubviewToFront:BtnEmail];
return currentCell;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[listTableView setEditing:editing animated:animated];
// Reload the table view
[listTableView reloadData];
// Do your other stuff
}
But it easy to create that button by using a custom cell. Here you are adding the button again and again. Otherwise move the button creating code to the if(cell == nil) block
That is because you are declaring
BtnEmail.hidden = FALSE;
which in this case is your last allocated button in cellForRowAtIndexPath method. Try something like this:
if(editing)
{
self.navigationItem.leftBarButtonItem.enabled = NO;
//BtnEmail.frame=CGRectMake(355, 17, 25, 25);
For(int i=0; i< [tableArray count]; i++)
{
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]] ;
UIButton *btn=(UIButton *)[cell viewWithTag:i];
btn.hidden = TRUE;
}
}
else
{
self.navigationItem.leftBarButtonItem.enabled = YES;
//BtnEmail.frame=CGRectMake(265, 17, 25, 25);
For(int i=0; i< [tableArray count]; i++)
{
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]] ;
UIButton *btn=(UIButton *)[cell viewWithTag:i];
btn.hidden = FALSE;
}
}

How to save data of tableview cell

i am using custom checkbox buttons in my table view and want to save the selected cell's data to a mutable array.... can anyone help me... Thanks
create a mutable array to store your selected data, lets call it 'yourSeparatedData' , set the tag of your checkbox in cellForRowAtIndexPath and set onCheck: method as target. the code will look like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = #"setMe";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyle………
}
checkBox = [UIButton buttonWithType:UIButtonTypeRoundedRect];
checkBox.frame = CGRectMake(customizeMe);
if(yourSeparatedData && [yourSeparatedData indexOfObject:[yourTableViewDataSource objectAtIndex:indexPath.row]] != NSNotFound)
{
[checkBox setBackgroundImage:[UIImage imageNamed:#"check.png"] forState:UIControlStateNormal];
}
else {
[checkBox setBackgroundImage:[UIImage imageNamed:#"unCheck.png"] forState:UIControlStateNormal];
}
[checkBox addTarget:self action:#selector(onCheck:) forControlEvents:UIControlEventTouchUpInside];
[checkBox setTag:indexPath.row];
[cell addSubview:checkBox];
return cell;
}
-(void)onCheck:(id)sender {
if(yourSeparatedData && [yourSeparatedData indexOfObject:[yourTableViewDataSource objectAtIndex:[sender tag]]] != NSNotFound)
{
[sender setBackgroundImage:[UIImage imageNamed:#"unCheck.png"] forState:UIControlStateNormal];
[yourSeparatedData removeObject:[yourTableViewDataSource objectAtIndex:[sender tag]]];
}
else {
[sender setBackgroundImage:[UIImage imageNamed:#"check.png"] forState:UIControlStateNormal];
[yourSeparatedData addObject:[yourTableViewDataSource objectAtIndex:[sender tag]]];
}
[yourTableView reloadData];
}
this code is not tested, you are using checkbox so I assumed that you want to separate not just one data, at the end of the selection, you will have 'yourSeparatedData' with the objects picked from your tableView.
you can try custom action in UITableView cell for button prees,you can also use put a check box image and on click you can change the image as checked here is the code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:#"identifire"];
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"identifire"] autorelease];
cell.detailTextLabel.text=[id_Array objectAtIndex:indexPath.row];
cell.detailTextLabel.hidden=YES;
button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"n_cross" ofType:#"png"];
UIImage *buttonImage1 = [[UIImage alloc] initWithContentsOfFile:path1];
[button setImage:buttonImage1 forState:UIControlStateNormal];
[button addTarget:self
action:#selector(customActionPressed:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Custom Action" forState:UIControlStateNormal];
button.frame = CGRectMake(245.0f, 20.0f, 40.0f, 40.0f);
[cell addSubview:button];
[buttonImage1 release];
CGRect imageFrame=CGRectMake(10,8,50,50);
self.cellimage=[[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
self.cellimage.image=[imageIdArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:self.cellimage];
return cell;
}
-(void)customActionPressed :(id)sender
{
//Get the superview from this button which will be our cell
UITableViewCell *owningCell = (UITableViewCell*)[sender superview];
NSIndexPath *cell = [_tableView indexPathForCell:owningCell];
NSString *uid=[id_Array objectAtIndex:cell.row];
[id_Array removeObjectAtIndex:cell.row];
[_tableView reloadData];
[self performSelectorInBackground:#selector(ignoreRequest:) withObject:uid];
}
here i have an id_Array and on selection of a cell i just remove the object at that index
You have to do this manually, there is no facility in a UITableView or UITableViewController t o do this automatically.
When user selects any cell then in didSelectRowAtIndexPath you can add selected object dynamically.
[someMutableArr addObject:[tableArr objectAtIndex:indexPath.row]];
Try this
- (void)onButtonClick {
int numberOfSections = [tableView numberOfSections];
for (int section = 0; section < numberOfSections; section++) {
int numberOfRows = [tableView numberOfRowsInSection:section];
for (int row = 0; row < numberOfRows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
// Cell is selected
//here you can add that values into an array
} else {
// Cell is not selected
}
}
}
}

iPhone : How can we load a custom check mark image for row in tableview?

I want to show a custom checkmark and uncheckmark image for tableview cell when user select any row and when a new row is inserted cell is loaded with uncheckmark image.
Once I check the row then even after reloading table with new data I want to display a previously checked row as it is and new as unchecked.
How can I get all rows with checked mark at end.
I tried but I am not able to load first time with custom checkmark image I can change when row is deselected but its also having some issues as it is not consistently working as I mentioned above.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [cardData.mArrRecipient count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * sCellIdentifier = #"cell";
NSLog(#"cellforrow");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sCellIdentifier] autorelease];
RecipientData *recipientData = [[cardData.mArrRecipient objectAtIndex:indexPath.row]autorelease];
cell.textLabel.text = recipientData.sRecipientFName;
}
cell.accessoryType=UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (IndexPath)
{
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"img_checkmark_red.png"]] autorelease];
[tableView cellForRowAtIndexPath:indexPath].accessoryView = imageView;
IndexPath=FALSE;
}
else
{
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"img_uncheckmark_red.png"]] autorelease];
[tableView cellForRowAtIndexPath:indexPath].accessoryView = imageView;
IndexPath=TRUE;
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([cardData.mArrRecipient count]>0)
{
[IBTblNewRecipientDetail reloadData];
}
}
can any one help me on this??
here is tutorial
http://weheartgames.com/2009/06/simple-iphone-checkbox/
or use this
UIButton * checkBox=[UIButton buttonWithType:UIButtonTypeCustom];
checkBox.tag=indexPath.row;
checkBox.frame=CGRectMake(270,15, 20, 20);
[cell.contentView addSubview:checkBox];
[checkBox setImage:[UIImage imageNamed:#"selectedBoxWith.png"] forState:UIControlStateNormal];
[checkBox addTarget:self action:#selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];
-(void)checkBoxClicked:(id)sender{
if(self.isChecked ==NO){
self.isChecked =YES;
[sender setImage:[UIImage imageNamed: #"selectedBoxWithTik.png"] forState:UIControlStateNormal];
}else
{
self.isChecked =NO;
[sender setImage:[UIImage imageNamed:#"selectedBoxWith.png"]forState:UIControlStateNormal];
}
}
and
-(void)checkBoxClicked:(id)sender{
UIButton *tappedButton = (UIButton*)sender;
if([tappedButton.currentImage isEqual:[UIImage imageNamed:#"selectedBoxWith.png"]]) {
[sender setImage:[UIImage imageNamed: #"selectedBoxWithTik.png"] forState:UIControlStateNormal];
}
else {
[sender setImage:[UIImage imageNamed:#"selectedBoxWith.png"]forState:UIControlStateNormal];
}
}
For selecting multiple rows:
- (void)addTableView {
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake("whatever frame you want to set")
style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.timeSheetEntryTableView.allowsMultipleSelection = YES;
self.array = [[NSMutableArray alloc]init];
[self.view addSubview:self.tableView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = #"Cell Identifier";
self.cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!self.cell) {
self.cell = [[Cell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
self.cell.accessoryType = UITableViewCellAccessoryNone;
}
self.cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([self.array containsObject:indexPath])
{
[self.cell.checkImage setImage:[UIImage imageNamed:#"check_box_selected.png"]];
}
else
{
[self.cell.checkImage setImage:[UIImage imageNamed:#"check_box.png"]];
}
return self.cell;
}
//did select and deselect I have used custom cell
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.cell = [tableView cellForRowAtIndexPath:indexPath];
[self.array addObject:indexPath];
[self.cell.checkImage setImage:[UIImage imageNamed:#"check_box_selected.png"]];
}
- (void)tableView:(UITableView *)tableView
didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
self.cell = [tableView cellForRowAtIndexPath:indexPath];
[self.array removeObject:indexPath];
[self.cell.checkImage setImage:[UIImage imageNamed:#"check_box.png"]];
}

passing the toggle button value to switch button state in another class in iphone

i have an application in which i have 2 tableview controller.In first tableview, i have a button created in my cellforRowAtIndexPath of my first tableview. Initially i have set the button image to 'ON' image which means my alarm is on .Then when i click on the edit button my tableview changes to editmode where i can change my button image to 'OFF'.i want that my button action should be called when the tableview enters in edit mode.This is the code that i have written.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:#"Cell%d%d", indexPath.section, indexPath.row];
appDelegate = (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate];
TAlarmCell *cell =(TAlarmCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TAlarmCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
mimageButton = [UIButton buttonWithType:UIButtonTypeCustom];
mimageButton.frame=CGRectMake(10, 20, 20, 20);
mimageButton.tag = 1;
[mimageButton setImage:[UIImage imageNamed:#"alarm_ON.png"] forState:UIControlStateNormal];
[mimageButton setImage:[UIImage imageNamed:#"alarm_OF.png"] forState:UIControlStateSelected];
[cell.contentView addSubview:mimageButton];
}
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
//this is my edit code.
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[mTableView setEditing:editing animated:YES];
if (editing)
{
[mimageButton addTarget:self action:#selector(changeMapType:) forControlEvents: UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = nil;
}
else {
self.navigationItem.rightBarButtonItem = addButton;
[self.mTableView reloadData];
}
}
//this is my button action
-(void)changeMapType:(UIButton *)sender
{
NSIndexPath *indexPath =[self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSUInteger row = indexPath.row;
NSLog(#"row...%d",row);
appDelegate.changeimagetype = !appDelegate.changeimagetype;
sender.selected = appDelegate.changeimagetype;
[self.tableView reloadData];
}
But the problem here is when i click on edit button and tableview enters in edit mode,changeMapType: action is not getting called and my image does not changes.
can u give me some details about
where u r setting this flag
if (editing)
and for which action of user u want this method to get to called..?
-(void)changeMapType:(UIButton *)sender
if u want to get called immediately after entering into edit mode, u can use the below method
[self performSelector:#selector(changeMapType:)];