Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton not responding to click event in UITableViewCell
    primarykey
    data
    text
    <p>there is this dark sorcery in ios is preventing my button being clicked. if i don't add button to the uitableviewcell, and i click the button, the event is triggered. but if the button is in uitableviewcell, it won't get triggered, it seems table i have sample code ready, if you guys can help me, please just create a simple single-view application in xcode, and just paste the following code</p> <p>//GRDViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface GRDViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt; @property (nonatomic, strong) UIView* container; @property (nonatomic, strong) UIButton* button; @property (nonatomic, strong) UITableView* tableView; @property (nonatomic, strong) NSArray* arr; @end </code></pre> <p>//GRDViewController.m</p> <pre><code>#import "GRDViewController.h" @implementation GRDViewController @synthesize button, container, arr, tableView; - (void)_btnTapped { NSLog(@"TAPPED"); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; [self.button addTarget:self action:@selector(_btnTapped) forControlEvents:UIControlEventTouchUpInside]; [self.button setTitle:@"CLICK ME" forState:UIControlStateNormal]; self.arr = [[NSArray alloc] initWithObjects:@"123", @"456", @"678", nil]; self.container = [[UIView alloc]initWithFrame:self.button.frame]; [self.container addSubview:self.button]; [self.view addSubview:self.container]; //[self.view addSubview:self.button]; self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, 400, 400)]; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.delegate = self; self.tableView.dataSource = self; [self.view addSubview:self.tableView]; self.tableView.backgroundColor = [UIColor redColor]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { static NSString *cellIdentifier = @"coolcell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; //cell.accessoryType = UITableViewCellAccessoryNone; UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)]; [btn addTarget:self action:@selector(_btnTapped) forControlEvents:UIControlStateNormal]; [btn setTitle:[self.arr objectAtIndex:[indexPath row]] forState:UIControlStateNormal]; [cell.contentView addSubview:btn]; } return cell; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { return [self.arr count]; } @end </code></pre> <p>please help i feel this case should be common in ios, but nobody has solution for this???</p> <p>edit: when click on the button it prints NSLOG msg in the xcode console...so make sure...u r looking at the results there...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload