0
Je veux créer un événement de clic sur le bouton,Comment ajouter un événement sur un clic d'un bouton UITableViewCell dans Xcode
Cet événement devrait prendre le texte d'un champ de texte correspondant et impression est comme une étiquette pour une cellule précédente .
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *[email protected]"cellidentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(cell==nil)
{
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier]autorelease];
}
if((indexPath.row%2)==0)
{
UILabel* lblnames=[[UILabel alloc]initWithFrame:CGRectMake(5,5 ,170 ,25)];
[lblnames setText:[listoffriends objectAtIndex:indexPath.row]];
[lblnames setTag:indexPath.row];
cell.contentView.backgroundColor=[UIColor purpleColor];
[cell.contentView addSubview:lblnames];
}
else
{
UITextField* txtn=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, 150, 25)];
txtn.delegate=self;
[txtn setTag:indexPath.row];
UIButton*btnclkd=[[UIButton buttonWithType:UIButtonTypeRoundedRect]retain];
btnclkd.frame=CGRectMake(200, 5, 70, 25);
[btnclkd setTag:indexPath.row];
[btnclkd setTitle:@"OK" forState:UIControlStateNormal] ;
[btnclkd addTarget:self action:@selector(btnok:)forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btnclkd];
cell.contentView.backgroundColor=[UIColor lightGrayColor];
[cell.contentView addSubview:txtn];
}
return cell;
}
-(void)btnok:(id)sender
{
int tag=([sender tag]);
NSLog(@"%d",tag);
}