Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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 如何在自定义单元格中查找按钮框的x、y位置_Iphone_Objective C_Frame_Cgrect_Custom Cell - Fatal编程技术网

Iphone 如何在自定义单元格中查找按钮框的x、y位置

Iphone 如何在自定义单元格中查找按钮框的x、y位置,iphone,objective-c,frame,cgrect,custom-cell,Iphone,Objective C,Frame,Cgrect,Custom Cell,我创建了一个带有自定义单元格的表视图,如下所示 !![自定义单元格][1] !![输出表格视图][2] 我需要在每个单元格中使用选择器而不是滑块来设置分级 我只需要在按钮下方设置选择器位置,它将随按钮位置的不同而变化 如何实现它 iu尝试了以下fram&bounds,但每次都给出相同的值 - (IBAction) buttonClicked:(UIButton *)sender { NSLog(@"------%f %f",sender.fram

我创建了一个带有自定义单元格的表视图,如下所示

!![自定义单元格][1]

!![输出表格视图][2]

我需要在每个单元格中使用选择器而不是滑块来设置分级

我只需要在按钮下方设置选择器位置,它将随按钮位置的不同而变化

如何实现它

iu尝试了以下fram&bounds,但每次都给出相同的值

   - (IBAction) buttonClicked:(UIButton *)sender
    {      
          NSLog(@"------%f  %f",sender.frame.origin.x , sender.frame.origin.y); //250, 2

         NSLog(@"------%f  %f",sender.bounds.origin.x , bounds.frame.origin.y); // 0.0 , 0.0

       picker.frame = CGRectMake(sender.bounds.origin.x , sender.bounds.origin.y, 50, 216);
}

您在最后一行中有一个输入错误,您两次使用“.x”值,而不是第二次使用“.y”值

此外,还需要将坐标转换为显示拾取器的视图的坐标。包括显示选择器的代码,我可以帮你

它将是这样的:

picker.frame = [viewThatYouAreDisplayingThePickerIn convertRect:sender.frame fromView:sender.superview];

但是,如果您想获得与主视图相关的按钮框架,请使用以下命令:

 CustomCell *cell = (CustomCell *)[self.table cellForRowAtIndexPath:indexPath];

 CGRect buttonFrame = [cell.superview convertRect:cell.customButton.frame toView:self.view];

按钮具有一个名为
locationInView
的方法,该方法继承自
UITouch

Returns the current location of the receiver in the coordinate system of the given view.
- (CGPoint)locationInView:(UIView *)view

您建议我们从哪里获得
indepath
?:-)当您当时在cellforrowatindexpath中创建单元格时,您可以将标记赋予按钮,然后使用该标记创建类似[NSIndexPath indexPathForRow:button.tag inSection:0]的indexpath。这是一种方法。。。。不过,对于他正在努力做的事情,似乎有很多工作要做。:)(顺便说一句,如果你出于其他原因想使用这种技术,那么使用表视图的
indexPathsForRowsInRect
方法要容易得多,如我前面的回答所示:而不是标记)。是的,你是对的,但是要得到“ViewThatYouareydisplayingthePickerin”,他一定有办法拿到桌子上的东西。。他需要一个indexPath来获取表单元格对象,不是吗?哦,好的,他可以使用superview方法(是的;)