Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在xcode中单击uitableviewcell中的按钮时添加事件_Ios_Xcode - Fatal编程技术网

Ios 如何在xcode中单击uitableviewcell中的按钮时添加事件

Ios 如何在xcode中单击uitableviewcell中的按钮时添加事件,ios,xcode,Ios,Xcode,我想在按钮上创建一个单击事件 此事件应为相应的文本字段获取文本,并将打印作为上一个单元格的标签 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellidentifier=@"cellidentifier"; UITableViewCell *cell=[tableView dequeueReus

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

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

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

这可能就是您想要称之为:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths 
              withRowAnimation:(UITableViewRowAnimation)animation  
在上,您需要请求重新加载行、节或整个表,以便修改可以反映在屏幕上