I just want to know .... add buttons to each cell in the row of the table ..... programmatically at run time and also wants to identify the button when clicked.
I am writing a little code .. here ....
//---insert individual row into the table view--- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]] autorelease]; } NSLog(@"i am here in table function..........now"); //cell.textLabel.text = [data objectAtIndex: indexPath.row]; search_items *pro = [searchCount objectAtIndex:[indexPath row]]; cell.textLabel.text = pro.s_showroomName; UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [aButton setTag:[indexPath row]]; [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:aButton]; return cell; } -(void)buttonClicked:(UIButton*)sender { int tag = sender.tag; ///and rest code here..... }
this code is not working properly .... :) please give me a solution :)
thanks in advance ..... please give me also a tutorial.
source share