Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Iphone 单击UITableView单元格的自定义按钮时无法识别当前单元格对象_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 单击UITableView单元格的自定义按钮时无法识别当前单元格对象

Iphone 单击UITableView单元格的自定义按钮时无法识别当前单元格对象,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我在UITableView中创建了两个自定义按钮。当我单击按钮1时,另一个按钮应该可见。为此,我使用以下代码。我正在使用UITableView分组数据类型 btnSettingButton=[[UIButton alloc]initWithFrame:CGRectMake(265, 50, 22, 22)]; [btnSettingButton setImage:[UIImage imageNamed:@"Settings Icon.png"] forState:UIControlStat

我在UITableView中创建了两个自定义按钮。当我单击按钮1时,另一个按钮应该可见。为此,我使用以下代码。我正在使用UITableView分组数据类型

   btnSettingButton=[[UIButton alloc]initWithFrame:CGRectMake(265, 50, 22, 22)];
[btnSettingButton setImage:[UIImage imageNamed:@"Settings Icon.png"] forState:UIControlStateNormal];
[btnSettingButton addTarget:self action:@selector(accessoryButtonTapped:withEvent:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:btnSettingButton];
[btnSettingButton setHidden:YES];



btnUncheck=[[UIButton alloc] initWithFrame:CGRectMake(265, 15, 18, 18)];

//btnUncheck=[UIButton buttonWithType:UIButtonTypeCustom];
btnUncheck.tag=indexPath.row;
[btnUncheck setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal];
     [btnUncheck addTarget:self action:@selector(buttonTapped:event:) forControlEvents:UIControlEventTouchUpInside];

[view addSubview:btnUncheck];   
[btnUncheck release];

[cell.contentView addSubview:view];

return cell;



 - (void)buttonTapped:(id)sender event:(id)event
{
CGPoint touchPosition = [[[event allTouches] anyObject] locationInView:self.tableV];
NSIndexPath *indexPath = [self.tableV indexPathForRowAtPoint:touchPosition];
if(favoriteChecked==NO)
   {


    [sender setImage:[UIImage imageNamed:@"YES.png"] forState:UIControlStateNormal];
    if(indexPath){
    [btnSettingButton setHidden:NO];
    }
    favoriteChecked=YES;


   }
   else
   {


    [sender setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal];
    [btnSettingButton setHidden:YES];
    favoriteChecked=NO;
   }


}
当我使用此代码时,它会将设置按钮显示到该部分的最后一个单元格


请指导我如何向单击的单元格显示settingButton。

btnSettingButton只有一个全局变量-当然它指向您创建的最后一个按钮


您必须保留对您创建的所有设置按钮的所有引用,然后在buttonTapped函数中获得正确的按钮。例如,您可以将所有引用添加到字典中,使用btnUncheck作为键-btnUncheck是您在按钮单击功能中获得的发送者,因此您可以从字典中获得相应的btnSettingButton。

实际上我没有清楚地了解您

我想您需要在tableview的单元格中添加一个按钮。如果单击此按钮,此图像将被更改


我说的对吗?

您是否在cellForRowAtIndexPath中添加了按钮?还是它的定制手机?shweta你能过来聊天吗?这是链接吗?[