1

我通过集成 8 个段的分段控件以编程方式创建了动态表的自定义单元格。

它运作良好,但一旦我点击其中一个部分,我希望在单元格附近出现一个带有选项的弹出菜单,而不是在表格视图的下端。

我想这是因为我已将 segue 锚定到 tableview。我想避免为每个段分配一个弹出菜单的segue。

是否有可能根据所选段自动重新定位弹出菜单?

这是主视图控制器.m文件中的相关代码

-(void)segmentSelectedAtRow: (UISegmentedControl *)sender{
if (self.flipsidePopoverController) {
    [self.flipsidePopoverController dismissPopoverAnimated:YES];
    self.flipsidePopoverController = nil;
} else {
    [self performSegueWithIdentifier:@"segueToChangeValues" sender:sender];
}

UITableViewCell *theParentCell = [[sender superview]superview];
NSIndexPath *indexPathOfSegment = [self.spreadSheetView indexPathForCell:theParentCell];

...
}

...

- (void)flipsideViewControllerDidFinish:(POTFlipsideViewController *)controller {

[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.flipsidePopoverController = nil;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueToChangeValues"]) {
    [[segue destinationViewController] setDelegate:self];
    UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
    self.flipsidePopoverController = popoverController;
    popoverController.delegate = self;
}
}

@end

这是另一面的 .h 文件

@class POTFlipsideViewController;

@protocol POTFlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(POTFlipsideViewController *)controller;
@end

@interface POTFlipsideViewController : UIViewController

@property (weak, nonatomic) id <POTFlipsideViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;
....
 @end

这是反面 .m 文件的相关代码

#import "POTFlipsideViewController.h"

@interface POTFlipsideViewController ()

@end

@implementation POTFlipsideViewController

- (void)awakeFromNib
{
self.contentSizeForViewInPopover = CGSizeMake(320.0, 480.0);
 [super awakeFromNib];
 }

 - (void)viewDidLoad
{
    [super viewDidLoad];

}
return YES;
}

 - (IBAction)done:(id)sender
 {
    [self.delegate flipsideViewControllerDidFinish:self];
}

@end
4

0 回答 0