我有一個帶有自定義tableview單元格的tableview。在tableview單元格中有兩個標籤和一個按鈕。我希望它激發用戶選擇的行的按鈕動作以隱藏同一行中的標籤。如何在iOS中的didselectrowatindexpath中觸發按鈕操作方法,目標c
這是我的表視圖控制器
ViweController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tablev;
@end
ViewController.m
#import "ViewController.h"
#import "TestTableViewCell.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycell"];
cell.selectionStyle = UITableViewCellFocusStyleCustom;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger sec = indexPath.section;
NSInteger rw = indexPath.row;
TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycell"];
cell.numberlabel.hidden = YES;
NSLog(@"selected section :%li ---> selected row :%li",(long)sec, (long)rw);
//in here I want fire the button acction in the cell for each row when cell tap.(not when the button click in the cell).
}
TestTableViewCell.h
#import <UIKit/UIKit.h>
@interface TestTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *staticlabel;
@property (weak, nonatomic) IBOutlet UILabel *numberlabel;
@property (weak, nonatomic) IBOutlet UIButton *hidebutton;
@end
TestTableViewCell.m //我試圖在這一點上它沒有認識到哪個小區錄音here.It worked.but實現按鈕點擊方法。
**注:我試圖在這裏實現按鈕單擊方法。我工作,但在那時它不能識別哪個單元格被錄製。 **
很好,非常感謝。我嘗試過不同的方式,沒有成功。這很棒。 –
你也可以通過diff way @ bhavin的answe來做到這一點,你也可以做到這一點 –