3

I made a table view with a custom cell as follows.

![Custom cell][1]

![Out put table view][2]

i need to set ratings using picker instead of slider in each cell

enter image description here

I need to set picker position only on just bellow the button it will varie with respective to the button postion

how to achieve it.

iu tried with fram & bounds as follow but give same vaues every time

   - (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);
}
user1811427
  • 359
  • 2
  • 6
  • 17

3 Answers3

6

You have a typo in your last line where you use the ".x" value twice, instead of using the ".y" value the second time.

Also, you need to convert the coordinates to the coordinates of the view that the picker is being displayed in. Include the code for showing your picker and I can help you with that.

It will be something like this:

picker.frame = [viewThatYouAreDisplayingThePickerIn convertRect:sender.frame fromView:sender.superview];
lnafziger
  • 25,760
  • 8
  • 60
  • 101
1

But still if you want to get the buttons frame with respect to main view Use this:

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

 CGRect buttonFrame = [cell.superview convertRect:cell.customButton.frame toView:self.view];
Bhupendra
  • 2,525
  • 18
  • 20
  • Where do you propose that we get `indexPath` from? :-) – lnafziger Jan 28 '13 at 06:56
  • when you created the cells in cellforrowatindexpath at that time you can give tag to buttons and then use that tag to create a indexpath like [NSIndexPath indexPathForRow:button.tag inSection:0] – Bhupendra Jan 28 '13 at 07:18
  • Well, that is one way to do it.... Seems like a lot of work though for what he is trying to do. :) (by the way, if you want to use this technique for other reasons, it is far easier to use the `indexPathsForRowsInRect` method of the table view as shown in my previous answer here: http://stackoverflow.com/a/14352372/937822 instead of tags). – lnafziger Jan 28 '13 at 07:22
  • yeah you are right lnafziger but as to get "viewThatYouAreDisplayingThePickerIn", he must have someway to get the object of the table cell .. and he needs a indexPath to get the table cell object isnt it ? – Bhupendra Jan 28 '13 at 07:25
  • Ohhh okayy he can use superview method yeah ;) – Bhupendra Jan 28 '13 at 07:26
  • Yeah, in this case he isn't displaying it in the cell anyway (he is showing it somewhere underneath the current cell) so won't need a reference to it. Probably in the table view, but it's hard to say for sure since he didn't post that portion of his code. – lnafziger Jan 28 '13 at 07:28
0

button has a method named locationInView inherited from UITouch

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

Apple Developer Reference

fengd
  • 7,551
  • 3
  • 41
  • 44