我想在按钮上创建一个点击事件,
此事件应为相应的文本字段获取文本,并将打印作为前一个单元格的标签。
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellidentifier=@"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);
}