【发布时间】:2016-07-06 06:22:50
【问题描述】:
我有一个带有自定义表格视图单元格的表格视图。在 tableview 单元格中有两个标签和一个按钮。我希望它为用户选择的行触发按钮操作以隐藏同一行中的标签。
这是我的表格视图控制器
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 //我试图在这里实现按钮单击方法。它有效。但那时它没有识别出哪个单元格被录音。
**注意:我试图在这里实现按钮单击方法。我工作过。但那时它没有识别出哪个单元格被录音。 **
【问题讨论】:
标签: ios objective-c button tableview didselectrowatindexpath