UIButton TouchUpInside or any other event not working properly in UITableView Custom Cell. Some time touch works if i press button in corner.
Actually i want to reorder cell at any time so i enabled edit mode.
[_profileTblView setEditing:YES animated:YES];
_profileTblView.allowsSelectionDuringEditing=YES;
If i disable edit mode then UIButton event working properly but i can't reorder the cell. Here i want both work together.
So, what will be the solution for this..
My Cell looks like
Cell's Prototype looks like
At your Custom Cell End,
1) Make protocol of your custom cell's .h file like
@protocol CustomCellDelegate
@optional
- (void)ButtonTappedOnCell:(id)sender;
@end
2) Set delegate in your .h file and set Custom Cell's button on click method
@property (nonatomic, strong) id<CustomCellDelegate> delegate;
- (IBAction)buttonTapped:(id)sender;
3) In your .m file,
- (IBAction)buttonTapped:(id)sender {
[self.delegate ButtonTappedOnCell:self];
}
4) Link that IBAction with Button
5) Uncheck Use Autolayout of your Custom Cell
At your Table View end,
1) Set Delegate of Custom Cell
@interface SomeViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, CustomCellDelegate>
2) In - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath , set the cell's delegate cell.delegate=self
.
3) Implement new made Delegate's function according to your need ie
- (void)ButtonTappedOnCell:(id)sender
{
//your logic
}
Hope that helps you.
Cheers
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"" forIndexPath:indexPath];
[cell.buttnName2 addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
return Cell;
}
//action for button
- (void)BtnAction:(id)sender//type 1 button action
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.