没有尺寸的弹出框

发布于 2024-12-12 10:05:05 字数 3138 浏览 8 评论 0原文

我制作了一个弹出窗口类,我可以轻松地调用它来实现基本弹出窗口 - 您为其提供数据并设置大小,它应该完成其余的工作。

在 iOS5 之前,这一切都运行良好,现在弹出窗口会打开,但只有边框,根本没有空白或内容。

我搜索了又搜索,你能提出的任何想法都会很棒。

@protocol BasicPickerDelegate
 - (void)basicPickerItemSelected:(NSMutableDictionary *)thisDic; 
@end


@interface BasicPickerController : UITableViewController {

 // data

 IBOutlet NSMutableArray *theData;

 // stuff to set 

 IBOutlet int myWidth;
 IBOutlet int myHeight;

 IBOutlet int myPopoverNum;

 // delegate
 id<BasicPickerDelegate> delegate;      

}

 @property (nonatomic, retain) IBOutlet NSMutableArray *theData;

 @property (nonatomic, assign) IBOutlet int myWidth; 
 @property (nonatomic, assign) IBOutlet int myHeight;
 @property (nonatomic, assign) IBOutlet int myPopoverNum;

 @property (nonatomic, assign) id<BasicPickerDelegate> delegate;

 - (void)setSize;
 - (void)checkData;

@end

然后 setSize 函数是 viewDidLoad

- (void)setSize {

    if (!myWidth || !myHeight) {

      NSLog(@"WIDTH AND HEIGHT NOT SET, SETTING DEFAULTS");
      myWidth = 100;
      myHeight = 100;

    }

    self.contentSizeForViewInPopover = CGSizeMake(myWidth, myHeight);
}

然后我这样调用它:

- (IBAction)showBasicPopover:(id)sender {

    // Show Basic Popover - can be reused

    if (basicPicker != nil) {

        self.basicPicker = nil;
        [self.basicPicker release];

    }

    self.basicPicker = [[[BasicPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease];

    basicPicker.delegate = self;

    self.basicPickerPopover = [[[UIPopoverController alloc] 
                                    initWithContentViewController:basicPicker] autorelease];      

    // Give popover the data it needs

    NSMutableDictionary *sizeDic = [self returnPopoverSize:[sender tag]];

    self.basicPicker.myHeight = [[sizeDic objectForKey:@"height"] intValue];
    self.basicPicker.myWidth = [[sizeDic objectForKey:@"width"] intValue];
    self.basicPicker.myPopoverNum = [sender tag];

    [basicPicker viewDidLoad];

    self.basicPicker.theData = [self returnPopoverData:[sender tag]];

    NSLog(@"giving popover dic (%d) with %d derps", [sender tag], [self.basicPicker.theData count]);

    // Set display settings and show popover

    [basicPicker viewWillAppear:YES];

    CGRect popoverRect = [self.view convertRect:[sender frame] 
                                       fromView:[sender superview]];

    [self.basicPickerPopover presentPopoverFromRect:popoverRect 
                                             inView:self.view 
                           permittedArrowDirections:UIPopoverArrowDirectionAny 
                                           animated:YES];

}

当我运行它时,会出现 WIDTH AND HEIGHT NOT SET, SETTIN DEFAULTS 对话框。由于某种原因,它没有读取给定的值。尽管经过一些摆弄,即使我可以让它读取它们,但它也不认为它们是有效的并覆盖它们。

编辑:所以基本上:

在 viewDidLoad 中调用 setSize 时,它​​不知道宽度和高度是多少。所以它设置了默认值。

如果在 viewDidLoad 中没有调用 setSize,它会显示“无大小” - 即它有弹出框边框,但其中根本没有内容。

当在 viewWillAppear、viewDidAppear 或类似的东西中调用 setSize 时(在 viewDidLoad 之后),它实际上并没有设置弹出窗口的大小。

I made a popover class that I could call easily for basic popovers - you give it data and set the size and it should do the rest.

This was working fine until iOS5, now the popover opens but with just the border, no white space or content at all.

I've searched and searched, any ideas you could throw my way would be great.

@protocol BasicPickerDelegate
 - (void)basicPickerItemSelected:(NSMutableDictionary *)thisDic; 
@end


@interface BasicPickerController : UITableViewController {

 // data

 IBOutlet NSMutableArray *theData;

 // stuff to set 

 IBOutlet int myWidth;
 IBOutlet int myHeight;

 IBOutlet int myPopoverNum;

 // delegate
 id<BasicPickerDelegate> delegate;      

}

 @property (nonatomic, retain) IBOutlet NSMutableArray *theData;

 @property (nonatomic, assign) IBOutlet int myWidth; 
 @property (nonatomic, assign) IBOutlet int myHeight;
 @property (nonatomic, assign) IBOutlet int myPopoverNum;

 @property (nonatomic, assign) id<BasicPickerDelegate> delegate;

 - (void)setSize;
 - (void)checkData;

@end

Then the setSize function is viewDidLoad

- (void)setSize {

    if (!myWidth || !myHeight) {

      NSLog(@"WIDTH AND HEIGHT NOT SET, SETTING DEFAULTS");
      myWidth = 100;
      myHeight = 100;

    }

    self.contentSizeForViewInPopover = CGSizeMake(myWidth, myHeight);
}

Then I call it like this:

- (IBAction)showBasicPopover:(id)sender {

    // Show Basic Popover - can be reused

    if (basicPicker != nil) {

        self.basicPicker = nil;
        [self.basicPicker release];

    }

    self.basicPicker = [[[BasicPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease];

    basicPicker.delegate = self;

    self.basicPickerPopover = [[[UIPopoverController alloc] 
                                    initWithContentViewController:basicPicker] autorelease];      

    // Give popover the data it needs

    NSMutableDictionary *sizeDic = [self returnPopoverSize:[sender tag]];

    self.basicPicker.myHeight = [[sizeDic objectForKey:@"height"] intValue];
    self.basicPicker.myWidth = [[sizeDic objectForKey:@"width"] intValue];
    self.basicPicker.myPopoverNum = [sender tag];

    [basicPicker viewDidLoad];

    self.basicPicker.theData = [self returnPopoverData:[sender tag]];

    NSLog(@"giving popover dic (%d) with %d derps", [sender tag], [self.basicPicker.theData count]);

    // Set display settings and show popover

    [basicPicker viewWillAppear:YES];

    CGRect popoverRect = [self.view convertRect:[sender frame] 
                                       fromView:[sender superview]];

    [self.basicPickerPopover presentPopoverFromRect:popoverRect 
                                             inView:self.view 
                           permittedArrowDirections:UIPopoverArrowDirectionAny 
                                           animated:YES];

}

When I run it, the WIDTH AND HEIGHT NOT SET, SETTIN DEFAULTS dialogue comes up. For some reason it's not reading in the values it's given. Though with some fiddling, even if I can get it to read them in it don't think they are valid and overrides them.

edit: So basically:

With setSize being called in viewDidLoad it doesn't know what the width and height is. So it sets the default.

If setSize isn't called in viewDidLoad, it comes up with "no size" - ie it has popover border but no content in it at all.

When setSize is called in viewWillAppear, viewDidAppear or anything like that (after viewDidLoad) it doesn't actually set the size of the popover.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饭团 2024-12-19 10:05:05

终于明白了这一点。

我需要在创建弹出窗口之后、初始化它之前分配宽度/高度变量。

修改后的代码如下:

self.basicPicker = [[[BasicPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease];

// Give popover the data it needs

basicPicker.delegate = self;

NSMutableDictionary *sizeDic = [self returnPopoverSize:[sender tag]];

self.basicPicker.myHeight = [[sizeDic objectForKey:@"height"] intValue];
self.basicPicker.myWidth = [[sizeDic objectForKey:@"width"] intValue];
self.basicPicker.myPopoverNum = [sender tag];

// Now init

self.basicPickerPopover = [[[UIPopoverController alloc] 
                            initWithContentViewController:basicPicker] autorelease];      

[basicPicker viewDidLoad];

Finally figured this out.

I needed to assign the width/height variables after creating the popover but before initialising it.

Revised code below:

self.basicPicker = [[[BasicPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease];

// Give popover the data it needs

basicPicker.delegate = self;

NSMutableDictionary *sizeDic = [self returnPopoverSize:[sender tag]];

self.basicPicker.myHeight = [[sizeDic objectForKey:@"height"] intValue];
self.basicPicker.myWidth = [[sizeDic objectForKey:@"width"] intValue];
self.basicPicker.myPopoverNum = [sender tag];

// Now init

self.basicPickerPopover = [[[UIPopoverController alloc] 
                            initWithContentViewController:basicPicker] autorelease];      

[basicPicker viewDidLoad];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文