ios - Delete Label on Button Click and Other label Move Up -


i developing ios app. create label , button when select didselectrowatindexpath create properly. when clicked button delete label , button delete perfectly.but problem label's not move after deleted label , button. , change index value of label's after deleted label. please in advance.

code..    - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      y =  y + 40;     count++;      uitableviewcell *selectedcell = [self.tableview cellforrowatindexpath:indexpath];     nslog(@"%@",selectedcell);      nsstring *str = [array objectatindex:indexpath.row];      _label = [[uilabel alloc]initwithframe:cgrectmake(x,y, 200.0f, 30.0f)];     [_label.layer setbordercolor: [[uicolor blackcolor] cgcolor]];     [_label.layer setborderwidth: 1.0];     _label.text = str;     _label.tag = indexpath.row;     [self.view addsubview:_label];      _button =[[uibutton alloc]initwithframe:cgrectmake(220.0f,y, 30.0f, 30.0f)];     [_button.layer setbordercolor: [[uicolor blackcolor] cgcolor]];     [_button.layer setborderwidth: 1.0];     [_button settag:indexpath.row];     [_button addtarget:self action:@selector(buttontouchupinside:) forcontrolevents:uicontroleventtouchupinside];     [self.view addsubview:_button]; } - (ibaction)buttontouchupinside:(id)sender{      y = y - 40;      uibutton *button = (uibutton*)sender;     nsinteger index = button.tag;      [[sender viewwithtag:index] removefromsuperview];      _label = (uilabel *)[self.view viewwithtag:index];     [_label removefromsuperview];      _label =[[uilabel alloc]initwithframe:cgrectmake(x,y, 200.0f, 30.0f)];     _label.tag = index;     [self.view addsubview:_label];        _label = (uilabel *)[self.view viewwithtag:index + 1];     _label.frame = cgrectmake(x,y, 200.0f, 30.0f);     _label.tag = index;     [self.view addsubview:_label];      _button = (uibutton *)[self.view viewwithtag:index+1];     _button.frame = cgrectmake(220.0f,y, 30.0f, 30.0f);     _button.tag = index;     _button.backgroundcolor =[uicolor bluecolor];     [self.view addsubview:_button]; } 

i think need remove code in method buttontouchupinside

_label =[[uilabel alloc]initwithframe:cgrectmake(x,y, 200.0f, 30.0f)];  _label.tag = index;  [self.view addsubview:_label]; 

because adding new label @ same frame

and write method way

- (ibaction)buttontouchupinside:(id)sender{      y = y - 40;      uibutton *button = (uibutton*)sender;     nsinteger index = button.tag;      [[sender viewwithtag:index] removefromsuperview];      _label = (uilabel *)[self.view viewwithtag:index];     [_label removefromsuperview];        _label = (uilabel *)[self.view viewwithtag:index + 1];     _label.frame = cgrectmake(x,y, 200.0f, 30.0f);     _label.tag = index;       _button = (uibutton *)[self.view viewwithtag:index+1];     _button.frame = cgrectmake(220.0f,y, 30.0f, 30.0f);     _button.tag = index;     _button.backgroundcolor =[uicolor bluecolor];  } 

no need statement

[self.view addsubview:_label];  [self.view addsubview:_button]; 

once added in view


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -