我在每个部分都有一个UIButton,每次用户点击UIButton时我想显示一个UIPopover。我能够显示弹出窗口,但问题是,即使我点击UITableView中的其他部分,弹出窗口也仅显示在第一部分。下面是我为显示popover而编写的代码。
UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
UIView *popoverView = [[UIView alloc] init]; //view
popoverView.backgroundColor = [UIColor clearColor];
UIDatePicker *datePicker=[[UIDatePicker alloc]init];//Date picker
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
[datePicker addTarget:self action:@selector(result) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:headerBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
提前致谢。
答案 0 :(得分:0)
预计,您需要将headerbtn
的引用保持为唯一,并为每tag
使用section
属性;
尝试类似的东西:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ....
headerbtn.tag = indexPath.section+25;
}
标题行动
NSIndexPath *selectedIP = [NSIndexPath indexPathForRow:0 inSection:btn.tag - 25];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:selectedIP];
// Use the cell reference to point out the popOver
// ...........
[popoverController presentPopoverFromRect:[cell convertRect:btn.frame toView:self.view] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];