让 UIImagePickerView 在 iPad 应用程序的 UITableView 中工作
我有一个小问题。我正在开发一个 iPad 应用程序,其中有一个 UItableView。在该表格内,每个单元格中的完美位置都有按钮。现在,当用户单击这些按钮时,我希望打开一个 UIImagePickerView,以便他可以选择图像并将其设置在那里。
现在,我正在使用 UIPopOver 的对象打开 imagePicker,这就是我面临问题的地方。我需要 popOver 指向按钮单击它的完美位置。假设表中第三行的按钮调用它,则 popOver 应相应打开。
我使用此代码打开 popOver 并设置其框架:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
CGRect fr = tblView.frame;
fr.origin.x = fr.origin.x + btnActive.frame.origin.x;
fr.origin.y = fr.origin.y + btnActive.frame.origin.y;
fr.size = CGSizeMake(320, 480);
popOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
//self.popoverController = popOver;
popOver.delegate = self;
[popOver presentPopoverFromRect:btnActive.frame
inView:tblView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePicker release];
现在,发生的情况是,每当我单击按钮的行时,popOver 仅指向第一个可见行。当用户单击 TableView 中的任何按钮时,我调用一个名为 - (void) setImage: (id) sender
的方法。我按如下方式分配按钮 btnActive:
UIButton *btn = (UIButton *)sender;
btnActive = btn;
我完美地获得了按钮的标签,但无法在完美的位置获得 popOver 点。我想这是因为每次 btnActive 的框架保持不变。我可能错了。请帮我解决这个问题。提前一百万致谢!
I have a small problem. I am working on an iPad app and in that I've a UItableView. Inside that table there are buttons in every cell at perfect position. Now, when the user clicks on those buttons I wish to open a UIImagePickerView so that he can select image and set it there.
Now, I am using UIPopOver's object to open the imagePicker and there is where I face the problem. I need the popOver to point at the perfect place to which button clicked it. Suppose the button from the 3rd row in the table calls it then the popOver should open accordingly.
I am using this code to open the popOver and set its frame:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
CGRect fr = tblView.frame;
fr.origin.x = fr.origin.x + btnActive.frame.origin.x;
fr.origin.y = fr.origin.y + btnActive.frame.origin.y;
fr.size = CGSizeMake(320, 480);
popOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
//self.popoverController = popOver;
popOver.delegate = self;
[popOver presentPopoverFromRect:btnActive.frame
inView:tblView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePicker release];
Now, here what happens is, whenever I click the rows of the button, the popOver points at the first visible row only. I call a method called - (void) setImage: (id) sender
when user clicks on any of those buttons in the TableView. And I assign the button btnActive as follows:
UIButton *btn = (UIButton *)sender;
btnActive = btn;
I get the tag of the button perfectly but I am not able to get the popOver point at the perfect place. I guess that is because every time the frame of btnActive remains the same. I might be wrong. Please help me with this issue. A million thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tblView
不是按钮的超级视图。尝试使用cell.contentView
或cell
,具体取决于 UITableViewCell 子类视图层次结构的布局方式。您必须确定在哪个单元格中单击了按钮。tblView
isn't the button's superview. try usingcell.contentView
orcell
depending on how you have the UITableViewCell subclass view hierarchy laid out. You'll have to determine which cell the button was clicked in.