我在UITableView cell
中有UITableView
。当我试图从搜索栏列表中添加新值时,我将这个值添加到表中并同时在新添加的单元格上显示弹出窗口,但有时候它的工作完美但没有时间它显示在我使用单元格的任何地方.frame我的代码是相同的下面我附加预期的结果屏幕短也请任何人知道然后帮助我
- (void)loadPopOver:(id)idDataObj {
NSDictionary *dictDataObj = (NSDictionary*)idDataObj;
//add the popOverControl
OrdersDetailPopViewController *orderDetailPopVC = [[OrdersDetailPopViewController alloc] init];
orderDetailPopVC.idParentDelegate = self;
CGSize sizeObj = [orderDetailPopVC initView:5 totalTextArea:0 dataForTableViews:[dictDataObj valueForKey:TAG_DATASOURCE] titles:[dictDataObj valueForKey:TAG_TITLES]];
if (sizeObj.height == 0 && sizeObj.width == 0) {
NSLog(@"API Error : Incomplete data sent.");
return;
}
//Point from where to show the popOverControl
CGRect cgRect;
if (indexPathLastSelected.section == -1 ) {
if([_isFromSearchBar isEqualToString:@"FROM_SEARCH_BAR"])
{
UITableViewCell *cell = [tableViewLeft cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
cgRect = cell.frame;
//cgRect.origin.y = 190;
cgRect.origin.y = 25;
//cgRect.origin.x =270;
}
else if([_isFromRightTable isEqualToString:@"FROM_RIGHT_TABLE"])
{
UITableViewCell *cell = [tableViewLeft cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
cgRect = cell.frame;
}
}
else {
UITableViewCell *cell = [tableViewLeft cellForRowAtIndexPath:indexPathLastSelected];
cgRect = cell.frame;
}
popOverFormInput = [[UIPopoverController alloc] initWithContentViewController:orderDetailPopVC];
popOverFormInput.contentViewController = orderDetailPopVC;
[popOverFormInput setPopoverContentSize:sizeObj];
popOverFormInput.delegate = self;
if (self.view.window != nil)
[popOverFormInput presentPopoverFromRect:cgRect inView:tableViewLeft permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
答案 0 :(得分:0)
您的项目中有很多时髦的代码,我强烈建议您进行修改。但就目前而言,我建议简化并使用像这样的方法
//Get the cell's frame that you're interested in
UITableViewCell *cell = [tableViewLeft cellForRowAtIndexPath:selectedindexPath]
//and then use that cell's frame to position your popover over it.
[popOverFormInput presentPopoverFromRect:[cell frame] inView:cell.contentView
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
答案 1 :(得分:0)
当您尝试使用CGRect弹出时,它可能不是superView的框架,否则您在某处滥用框架值。
最好得到(注意)tableView的NSIndePath。稍后可以使用它从中弹出>
对于Ex:
- (void)loadPopOver:(id)idDataObj {
NSIndexPath *selectedindexPath;
.
.
.
if([_isFromSearchBar isEqualToString:@"FROM_SEARCH_BAR"])
selectedindexPath = // [tableViewLeft cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
.
.
.
// Try this to pop your View
[self.popOver presentPopoverFromRect:[tableViewLeft rectForRowAtIndexPath:selectedindexPath] inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
答案 2 :(得分:0)
在调用方法时我只是把延迟 我修复了这个问题 [self performSelector:@selector(showPopOver)withObject:nil afterDelay:0.20];