0

我想在按钮上创建一个点击事件,

此事件应为相应的文本字段获取文本,并将打印作为前一个单元格的标签。

(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);
}    
4

1 回答 1

0

这可能就是您要调用的内容:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths 
              withRowAnimation:(UITableViewRowAnimation)animation  

UITableView上,您需要要求重新加载一行、部分或整个表,以便修改可以反映在屏幕上。

于 2013-01-05T17:38:26.797 回答