click button action in sequentially order in UITableView - ios

created 4x4 metrics button in UITableView.
I want to select the button in sequentially order.
// button Creation in cell for row Index
for (int i = 0; i< [buttonArray count]; i++)
{
int buttonSpace = 10 * i + 10;
NSLog(#"ButtonPosition:%d",buttonSpace + (i * 50));
cell.Button = [[CustomButton alloc] initWithFrame:CGRectMake(buttonSpace + (i * 50),35, 50, 50)];
cell.Button.layer.cornerRadius = 25;
[cell.Button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
cell.Button.buttonIndex = i;
[cell.ScrollView addSubview:cell.Button];
cell.ScrollView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
}
rowIndexValue = indexPath.row;
// Button action in view controller.
-(void)buttonAction:(CustomButton *)sender
{
if (rowIndexValue) {
int counter = (int)[sender buttonIndex];
if (counter == incrementValue)
{
sender.backgroundColor = [UIColor redColor];
counter += 1;
incrementValue = counter;
}
else{
sender.selected = NO;
}
}
}
The order of button action in sequential order, for any random row's.
user select 3rd row but selection row in third row start from 1st button then 2nd button then 3rd button finally 4th button.
4x4 - > 4 row for UITableview 4 button in each row. Once button is click it will be in disable Mode

Set proper value so that you can recognise button column as well as row position. buttonIndex is just saving i value so you will only get column position.You may set button.tag=indexPath.row and use it in the buttonAction method to know the row position.

Declare NSInteger tagValue globally in your viewController.
-(NSUInteger)getRowByBtn:(UIButton *)btn :(UITableView *)tblView
{
CGPoint center= btn.center;
CGPoint rootViewPoint = [btn.superview convertPoint:center toView:tblView];
NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:rootViewPoint];
NSLog(#"indexPath = %ld", (long)indexPath.row);
return indexPath.row;
}
With the help of above method you can get indexpath.row value from which you can determine the button for each row in the tableview.
[cell.Button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
-(void)buttonAction:(UIButton*)sender
{
UIButton *btn=(UIButton *)sender;
tagValue = [self getRowByBtn:btn :yourTableview];
[[self.view viewWithTag:tagValue]setUserInteractionEnabled:YES];
//or any other action
}

Set UIButton tag in CellForRowAtIndexPath
Like this :
[cell.btn_name addTarget:self action:#selector(onclick_button:) forControlEvents:UIControlEventTouchUpInside];
self.btn_name.tag=indexpath.row;
And
-(IBAction)onclick_button:(id)sender
{
int btn_index= ((UIView*)sender).tag;
NSLog(#"Btn index:%d",btn_index);
}

It fix the problem with below code.
-(void)buttonAction:(UIButton*)sender{
CGPoint center = sender.center;
CGPoint rootViewPoint = [sender.superview convertPoint:centre toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:rootViewPoint];
sender.userInteractionEnabled = NO;
sender.backgroundColor = [UIColor redColor];
CustomButton *enableNextButton = (CustomButton *) [[self.goalsTableView cellForRowAtIndexPath:indexPath] viewWithTag:sender.tag+1];
enableNextButton.userInteractionEnabled = YES;
}

Related

Getting TextField Text On Button Click

I am developing an IOS App. I am creating a text field and a button dynamically, and I want to get textfield's text on button click, but I'm getting an error:
[UIView setText:]: unrecognized selector sent to instance
Here is my code:
- (IBAction)customFieldAdd:(id)sender{
[_addfieldArray addObject:_field];
x = 10;
y = 10;
for( int i = 0; i < [_addfieldArray count]; i++ ) {
UITextField *copyfield = [[UITextField alloc]initWithFrame:CGRectMake(5.0, x + _field.frame.size.height, 195.0f, 30.0f)];
[copyfield setDelegate:self];
[copyfield setTag:i];
[_filterPossibleValueView addSubview:copyfield];
x = x+_field.frame.size.height+10;
UIButton *copyAddButton = [[UIButton alloc]initWithFrame:CGRectMake(202.0f, y + _addField.frame.size.height, 30.0f, 30.0f)];
[copyAddButton setTag:i];
[copyAddButton addTarget:self action:#selector(customFieldDelete:) forControlEvents:UIControlEventTouchUpInside];
[_filterPossibleValueView addSubview:copyAddButton];
y = y+_addField.frame.size.height+10;
count++;
}
}
- (IBAction)customFieldDelete:(id)sender{
UIButton *button = (UIButton*)sender;
NSInteger index = button.tag;
// [_addfieldArray removeObjectAtIndex:index];
UITextField *field = [_filterPossibleValueView viewWithTag:index];
NSString *myText = field.text;
}
The default value for the tag property is 0, and you are setting that value to one of the text fields. So, when you try to get the view with tag == 0, it will have more than one view with that tag.
You should use an offset when setting the tag:
[copyfield setTag:kOffset + i];
...
[copyAddButton setTag:kOffset*2 + i]; // note that the button and the text field should not have the same tag either
where kOffset is defined (for example) like this:
let kOffset: Int = 1000
Then, to get the text field's text, you can use:
NSInteger tag = button.tag - kOffset;
UITextField *field = [_filterPossibleValueView viewWithTag:tag];
NSString *myText = field.text;

Showing Selected Buttons if Back button is Pressed [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
On first Page i am having some buttons , if i press any button it will move to Second page , here if i press back button in the navigation bar it will move to first page
i have created the buttons dynamically based on the array count ,i want to show the selected button when i move back to first page , how can i do this ?Please help me to do this .here is the code that i have used for creating buttons
int buttonheight = 30;
int horizontalPadding = 20;
int verticalPadding = 20;
int totalwidth = self.view.frame.size.width;
int x = 10;
int y = 150;
for (int i=0; i<array.count; i++)
{
NSString* titre = [array objectAtIndex:i];
//
CGSize contstrainedSize = CGSizeMake(200, 40);//The maximum width and height
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:20.0], NSFontAttributeName,
nil];
CGRect frame = [titre boundingRectWithSize:contstrainedSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributesDictionary context:nil];
int xpos = x + CGRectGetWidth(frame);
if (xpos > totalwidth) {
y =y +buttonheight+ verticalPadding;
x = 10;
}
UIButton * word= [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.word = word;
NSLog(#"%#", NSStringFromCGRect(frame));
word = [UIButton buttonWithType:UIButtonTypeRoundedRect];
word.frame = CGRectMake(x, y, CGRectGetWidth(frame)+5, CGRectGetHeight(frame));
[word setTitle:titre forState:UIControlStateNormal];
word.backgroundColor = [UIColor colorWithRed:30.0/255.0 green:134.0/255.0 blue:255.0/255.0 alpha:1.0];
[word setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[word setTag:i];
[word addTarget:self action:#selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];
word.layer.borderColor = [UIColor blackColor].CGColor;
word.layer.borderWidth = 1.0f;
word.layer.cornerRadius = 5;
[self.view addSubview:word];
x =x+horizontalPadding+CGRectGetWidth(frame);
}
- (IBAction)btn1Tapped:(id)sender {
NSString *btnTitle;
btnTitle = [(UIButton *)sender currentTitle];
NSLog(#"%#",self.title);
ReasonViewController *ReasonVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ReasonVC"];
ReasonVC.btnTitle = btnTitle;
NSLog(#"%#",self.imageArray);
ReasonVC.imageArray1 = self.imageArray;
[self.navigationController pushViewController:ReasonVC animated:YES];
}
=====Appdelegate.h========
#property (assign, nonatomic) long int btnTag;
=======CategoryViewController.h============
import "AppDelegate.h"
#interface CategoryViewController : UIViewController
{
AppDelegate *appdel;
}
===========CategoryViewController.m=======
add code
if(appdel.btnTag == word.tag)
{
word.selected = YES;
}
below [word setTag:i]; code
then add
UIButton *btn = (UIButton *) sender;
appdel.btnTag = btn.tag;
in - (IBAction)btn1Tapped:(id)sender method
The UIButton object has different states included the "Selected state". You can set different background image or title for each state you want. When you press it you can change its state like this:
//After you inited your UIButton Object do this:
[button setBackgroundImage:selectedBGImage forState:UIControlStateSelected];
[button setBackgroundImage:deselectedBGImage forState:UIControlStateNormal];
//You can also find the title change method for state accordingly
- (void)buttonAction:(UIButton *)sender
{
sender.selected = !sender.selected;
//TODO
}
So, when you pop back, the button will keep its "selected" state.
You have to store button tag in appdelegate and while creating button check with button tag/i values and do selected. please see below code
in AppDelegate.h
#property (assign, nonatomic) int btnTag;
create an object of AppDelegate on your current ViewController then
AppDelegate *appdel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
int buttonheight = 30;
.
.
.
[word setTag:i];
if(word.tag == appdel.btnTag)//appdel is object of AppDelegate
{
word.selected = YES;
}
[word addTarget:self action:#selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];
word.layer.borderColor = [UIColor blackColor].CGColor;
word.layer.borderWidth = 1.0f;
word.layer.cornerRadius = 5;
[self.view addSubview:word];
x =x+horizontalPadding+CGRectGetWidth(frame);
}
- (IBAction)btn1Tapped:(id)sender {
UIButton *btn = (UIButton *) sender;
appdel.btnTag = btn.tag;
NSString *btnTitle;
btnTitle = [(UIButton *)sender currentTitle];
NSLog(#"%#",self.title);
ReasonViewController *ReasonVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ReasonVC"];
ReasonVC.btnTitle = btnTitle;
NSLog(#"%#",self.imageArray);
ReasonVC.imageArray1 = self.imageArray;
[self.navigationController pushViewController:ReasonVC animated:YES];
}
enter image description here
I am getting like below screenshot , if i tapped any button it will move to next page and the backgroundcolor is changed to red color,and come back to same page by clicking back and now i tapped another button it is also showing in red color.
I have use this two lines in button action method :
UIButton *btn = (UIButton *) sender;
[btn setBackgroundColor:[UIColor redColor]];

How to use scrollRectToVisible:animated?

I have tableView and in one of the rows I have a horizontal scrollView and some images(images are in different view of the row), In horizontal scrollView i have added few buttons (10 buttons). when user clicks on any button from scrollView I call reloadData. Because I call reloadData so horizontal scrollView reloads again with new image Data. Now I want if user scrolls to end and clicked the last button from the scrollView, user should be able to see that selected button not the first one. I don't know how can i use scrollRectToVisible:animated to make this happen.
here is my code for scrollView and adding buttons on it.
-(void)addColorFiltersOnView:(UIView *)colorView{
if (_colorFilterView) {
[_colorFilterView removeFromSuperview];
}
self.colorFilterView = [[UIScrollView alloc] initWithFrame:colorView.bounds];
[_colorFilterView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[_colorFilterView setBackgroundColor:samergb(238)];
[_colorFilterView setShowsHorizontalScrollIndicator:NO];
int addedCount = 0;
int i=0;
CGFloat x = 10, y = 5;
if ([_colorFilters count] < 1) {
return;
}
for (i=0; i<[_colorFilters count] - 1; i++) {
id item = [_colorFilters objectAtIndex:i];
if ([item isKindOfClass:[NSString class]]){
if ([self.prodVIPDictionary.PDcolor isEqualToString:(NSString*)item] && i != 0) {
continue;
}
NSInteger itemsCount = [[_colorFilters objectAtIndex:i+1] integerValue];
if (itemsCount <= 0) {
break;
}
TTTAttributedLabel *itemLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
[itemLabel setNumberOfLines:1];
[itemLabel setTextAlignment:NSTextAlignmentCenter];
[itemLabel setFont:[UIFont systemFontOfSize:14]];
if ([_selectedColor isEqualToString:(NSString*)item])
[itemLabel setTextColor:[UIColor whiteColor]];
[itemLabel setText:[(NSString*)item capitalizedString]];
[itemLabel setBackgroundColor:samergb(255)];
itemLabel.layer.borderWidth = 1;
itemLabel.layer.masksToBounds = YES;
itemLabel.layer.cornerRadius = 10;
itemLabel.layer.borderColor = samergb(210).CGColor;
[itemLabel sizeToFit];
[_colorFilterView addSubview:itemLabel];
CGRect itemFrame = itemLabel.frame;
itemFrame.size.width += 20;
[itemLabel setFrame:itemFrame];
UIButton *optionBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, itemLabel.frame.size.width + 6, 26)];
[optionBtn setTag:[_colorFilters indexOfObject:item]];
[optionBtn addTarget:self action:#selector(optionColorClicked:) forControlEvents:UIControlEventTouchUpInside];
[_colorFilterView addSubview:optionBtn];
[itemLabel setFrame:optionBtn.frame];
if ([_selectedColor isEqualToString:(NSString*)item]) {
[optionBtn setEnabled:NO];
[itemLabel setBackgroundColor:[LRUtils lrGreenColor]];
}
addedCount ++;
x += optionBtn.frame.size.width+5;
if (addedCount >= 20) {
break;
}
}else{
continue;
}
}
[_colorFilterView setContentSize:CGSizeMake((x + 10),colorView.frame.size.height)];
[colorView addSubview:_colorFilterView];
}
Instead of calling reloadData, you could call this method on the Table View:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
You would need to create an NSArray containing all of the IndexPaths in the Table View except for the row with the scroll view and buttons. This way, the scroll view wouldn't get reset.

Change Button Text Color Programmatically for n number of buttons without changing Text Color of other button

I have n number of buttons in the scrollView. If click on a button its text color is changing but if I click another button the text color of the previous button remain unchanged. I want to change the previous button text color as default color while clicking another button. The behavior will be just like a segmented control. Please help me regarding this, I've providing my code below:
-(void) loadScrollView:(CGRect)scrollViewFrame withButtonArray:(NSArray*)buttonArray withCase: (int)ButtonCase
{
scrollView=[[UIScrollView alloc]initWithFrame:scrollViewFrame];
[scrollView setScrollEnabled:YES];
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setContentSize:CGSizeMake(100 * 768, 40)];
for (int i = 0; i < [buttonArray count]; i++)
{
adButtonOutLet = [[UIButton alloc] initWithFrame:CGRectMake(140*i, 0, 135, 40)];
if (ButtonCase==0) {
[adButtonOutLet setBackgroundColor:UIColorFromRGB(0X272c2f)];
[adButtonOutLet setTitleColor:UIColorFromRGB(0x969696) forState:UIControlStateNormal];
}
else
{
if (i==0) {
adButtonOutLet.backgroundColor=UIColorFromRGB(0x000000) ;
[adButtonOutLet setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
}
}
adButtonOutLet.titleLabel.font=[UIFont fontWithName:#"MyriadPro" size:14.0];
[adButtonOutLet setTitle:[buttonArray objectAtIndex:i] forState:UIControlStateNormal];
adButtonOutLet.userInteractionEnabled= YES;
[adButtonOutLet setTag:i];
[adButtonOutLet addTarget:self action:#selector(adButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:adButtonOutLet];
[self.view addSubview:scrollView];
}
}
Here is my action method:
-(void)adButtonAction:(UIButton*)sender
{
for (int i = 0; i < [menuArray count]; i++)
{
int prevTag = 0;
if (sender.tag == i && Case==0)
{
[self reloadScrollViewwithButtonTag:i];
// [sender setSelected:YES];
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
prevTag=i;
}
if (Case==1) {
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
if (sender.tag==prevTag-1) {
[sender setBackgroundColor:UIColorFromRGB(0X272c2f)];
[sender setTitleColor:UIColorFromRGB(0x969696) forState:UIControlStateNormal];
}
}
}
}
Why don't you try changing all buttons style to no selected except the one that is on the sender parameter (selected button)?
-(void)adButtonAction:(UIButton*)sender{
for (int i = 0; i < [menuArray count]; i++)
{
if (sender == menuArray[i])
{
//Selected code style
}
else{
//No selected code style
}
}
}
Considering menuArray is an array with all buttons.
This way you check and modify all styles when a button is pressed.
Hope this could help you or at last give you a clue for resolve your problem.
I don' understand everything in your adButtonAction (what is menuArray?) method but I think what you need is simple, just adapt it to your method.
First create a NSMutableArray to keep reference on your button list:
for (int i = 0; i < [buttonArray count]; i++)
{
adButtonOutLet = [[UIButton alloc] initWithFrame:CGRectMake(140*i, 0, 135, 40)];
[myButtonArray addObject:adButtonOutlet];
....
Then in you action method, set the right color:
for (UIButton* b in myButtonArray){
if(b.tag == sender.tag){
[self setSelectedColor:YES forButton:b];
// Do what you want here
}
else{
[self setSelectedColor:NO forButton:b];
}
}
With:
-(void)setSelectedColor:(BOOL)selected forButton:(UIButton)button{
if(selected){
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
}
else{
[sender setBackgroundColor:UIColorFromRGB(0X272c2f)];
[sender setTitleColor:UIColorFromRGB(0x969696)forState:UIControlStateNormal];
}
}
Apply state vise( Normal,Selected ) title color of button.
Just persist a selected button reference as weak.
while user clicked on button set that button state as selected instead normal.
Change last selected button state Normal instead Selected.
Check out below code that will be help you
UIButton *selectedButton;
-(void)adButtonAction:(UIButton*)sender
{
UIButton *tempButton = sender;
if (selectedButton && selectedButton!=tempButton)
{
[selectedButton setSelected:NO];
}
[tempButton setSelected:YES];
selectedButton = tempButton;
}

Unable to replace the tags of UIButton(s)

I have say for example 7 UIButtons namely c1 to c7. Now I have assigned tags starting from 1 to 7 respectively for the UIButtons c1 to c7.
Now when I select c2 for example it is removed from superView so now the tag for c2 which was 2 is transferred to c3 , 3 to c4 and so on.
This is what I have tried but logic is not working properly. I have posted question with similar concern before but didn't get any proper response.
-(void)totesttheFunction
{
for(int i=0; i<7; i++)
{
UIButton *testHere = (UIButton*)[self.view viewWithTag:i];
if([testHere isSelected])
{
int backuptagFor = testHere.tag;
CGFloat diff = 30.0;
for(int j=i+1; j<7;j++)
{
UIButton *btnToReplace = (UIButton*)[self.view viewWithTag:j];
CGRect setRect = CGRectMake(btnToReplace.frame.origin.x-diff, btnToReplace.frame.origin.y, btnToReplace.frame.size.width, btnToReplace.frame.size.height);
btnToReplace.tag = backuptagFor;
[testHere removeFromSuperview];
}
}
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for(int itemIndex = 1; itemIndex <= 7; itemIndex++)
{
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(itemIndex*40, 10, 30, 30)];
btn.tag = itemIndex;
[self.view addSubview:btn];
if (itemIndex == 3 ||itemIndex == 4)
{
[btn setSelected:YES];
}
}
[self testFunction];
}
- (void)testFunction
{
int totalButtons = 7;
int totalRemovedButtons = 0;
for(int itemIndex = 1; itemIndex <= totalButtons; itemIndex++)
{
UIButton *testHere = ([[self.view viewWithTag:itemIndex] isKindOfClass:[UIButton class]])?(UIButton *)[self.view viewWithTag:itemIndex]:nil;
if([testHere isSelected])
{
[testHere removeFromSuperview];
NSLog(#"removed button with tag:%d",itemIndex + totalRemovedButtons);
for (int tempItemIndx = itemIndex + 1; tempItemIndx <= totalButtons; tempItemIndx++)
{
UIButton *nextButton = ([[self.view viewWithTag:tempItemIndx] isKindOfClass:[UIButton class]])?(UIButton *)[self.view viewWithTag:tempItemIndx]:nil;
nextButton.tag = tempItemIndx - 1;
}
itemIndex--;
totalRemovedButtons ++;
}
NSLog(#"loop run %d",itemIndex);
}
NSLog(#"-------------------------------------------------------------------");
//Checking the updated tags.
for(int itemIndex = 1; itemIndex <= (totalButtons - totalRemovedButtons); itemIndex++)
{
UIButton *testHere = ([[self.view viewWithTag:itemIndex] isKindOfClass:[UIButton class]])?(UIButton *)[self.view viewWithTag:itemIndex]:nil;
NSLog(#"New tags %d",testHere.tag);
}
}
Output:
loop run 1
loop run 2
removed button with tag:3
loop run 2
removed button with tag:4
loop run 2
loop run 3
loop run 4
loop run 5
loop run 6
loop run 7
---------------------
New tags 1
New tags 2
New tags 3
New tags 4
New tags 5
Apply below approach first delete old UI and re-generate new UI from scratch assign them same tags again
e.g. 123456 - No 4 deleted - 12356 - store remaining data - re-generate new UI from old data
now 12345
- (IBAction)actionDeletePrevEmp:(UIButton *)sender
{
// ********* DELETED OLD UI AND GENERATED DATA FROM OLD UI **********
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for (int BTNCounter = 1; BTNCounter < 8 ;BTNCounter++)
{
if (BTNCounter == sender.tag)
{ // do not add contents to array
// delete it from UI
[(UIButton *)[self.view viewWithTag:BTNCounter]removeFromSuperview];
continue;
}
}
// ************* GENERATING NEW UI WITH TEMP DATA **************
int empSizeCounter = 50;
for (int loopCounter = 0, BTNTagCounter = 1 ; BTNTagCounter < 7; loopCounter++)
{
viewPreviousEmployerList = [[UIView alloc]initWithFrame:CGRectMake(0.0, empSizeCounter, 320.0, 50.0)];
// viewPreviousEmployerList.backgroundColor = [UIColor blackColor];
deletePrevEmpButton = [UIButton buttonWithType:UIButtonTypeSystem];
//[deletePrevEmpButton setImage:[UIImage imageNamed:#"checkbox.png"] forState:UIControlStateNormal];
deletePrevEmpButton = [[UIButton alloc]initWithFrame:CGRectMake(264.0, 10.0, 30.0, 30.0)];
deletePrevEmpButton.backgroundColor = [UIColor blueColor];
deletePrevEmpButton.titleLabel.text = #"X";
deletePrevEmpButton.tag = BTNTagCounter;
if (loopCounter+1 > [tempArray count])
{
btnTemp.text = #"";
}
else
{
btnTemp.text = tempArray[loopCounter];
}
BTNTagCounter++;
[viewPreviousEmployerList addSubview:btnTemp];
[self.viewAddEmployer addSubview:viewPreviousEmployerList];
empSizeCounter = empSizeCounter + 50;
}
First you need to add all button in NSMutableArray and follow me, (here array name is _myArrayOfBtn)
Add button's method such like, (and make sure that each button's have same method name)
[myBuutonName addTarget:self action:#selector(totesttheFunction:) forControlEvents:UIControlEventTouchUpInside];
And method declaration is like,
-(void) totesttheFunction:(UIButton *)sender
{
[sender removeFromSuperview]; // just put this code.
[_myArrayOfBtn removeObjectAtIndex:sender.tag];
// replace tag of buttons
for(int i = 1; i < _myArrayOfBtn.count; i ++)
{
UIButton *btn = (UIButton *)[_myArrayOfBtn objectAtIndex:i]
btn.tag = i;
}
}

Resources