简体   繁体   English

弹出框内的iOS 7 UITableView

[英]iOS 7 UITableView inside a popover

I have a UITableView which has some custom styling. 我有一个具有一些自定义样式的UITableView。 This table view appears in two places in the app, one of which is inside a UIPopoverController. 该表视图出现在应用程序的两个位置,其中一个位于UIPopoverController内部。 However when the tableview is inside the popover it takes on the default tableview styling as stated in the UI Transition Guide under "Popover". 但是,当表视图位于弹出窗口内部时,它将采用默认的表视图样式,如《 UI过渡指南 》中“弹出菜单”中所述。

The problem I have is that there appears to be nowhere to change this behaviour. 我的问题是似乎没有地方可以改变这种行为。 Regardless of where I try and modify properties of the tableview the view inside the popover doesn't change. 无论我在哪里尝试修改tableview的属性,弹出框内的视图都不会改变。

Anyone dealt with this issue before or have any ideas? 有人以前处理过这个问题或有任何想法吗?

Here is the init method of LibraryProductView where I create the table view: 这是我创建表视图的LibraryProductView的init方法:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.sectionOrdering = [NSArray arrayWithObjects:
                                [NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DESCRIPTION],
                                [NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DOCUMENTS],
                                [NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_ACTIVE_INGREDIENTS],
                                [NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_PRODUCTS],
                                [NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_DOCUMENTS], nil];

        self.backgroundColor = [UIColor whiteColor];

        self.tableView = [[UITableView alloc] initWithFrame:CGRectInset(self.bounds, 10, 0) style:UITableViewStyleGrouped];
        self.tableView.backgroundColor = [UIColor whiteColor];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.separatorColor = [UIColor clearColor];
        self.tableView.showsVerticalScrollIndicator = NO;

        [self addSubview:self.tableView];
    }
    return self;
}

Here is where the containing view (LibraryProductView) is added to the popover: 这是将包含视图(LibraryProductView)添加到弹出窗口的位置:

- (IBAction)didTouchInformationButton:(id)sender
{
    if (_infoPopover != nil && _infoPopover.isPopoverVisible)
    {
        [_infoPopover dismissPopoverAnimated:YES];
        return;
    }

    CGSize preferredSize = CGSizeMake(600.0f, 500.0f);

    LibraryProductViewController* productController = [[[LibraryProductViewController alloc] initWithPreferredSize:preferredSize] autorelease];
    productController.filterByMyCompany = NO;
    productController.product = _activityInput.product;

    UINavigationController* nav = [[[UINavigationController alloc] initWithRootViewController:productController] autorelease];
    nav.title = _activityInput.product.name;

    RELEASE(_infoPopover);
    _infoPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
    _infoPopover.popoverContentSize = CGSizeMake(preferredSize.width, preferredSize.height + 46);
    [_infoPopover presentPopoverFromRect:_infoButton.frame inView:_infoButton permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

The LibraryProductView is created within viewDidLoad method of LibraryProductViewController. LibraryProductView是在LibraryProductViewController的viewDidLoad方法中创建的。

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.libraryProductView = [[LibraryProductView alloc] initWithFrame:(usingPreferredSize ? CGRectMake(0.0, 0.0, preferredSize.width, preferredSize.height) : self.view.bounds)];
    self.libraryProductView.dataSource = self;
    self.libraryProductView.delegate = self;

    [self.view addSubview:self.libraryProductView];
}

To set properties for the TableView you might do so in 要设置TableView的属性,您可以在

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    [tableView setBackgroundColor:[UIColor redcolor]];
    [tableView setSeparatorColor: [UIColor blueColor]];

    return 1;
}

This, of course, assumes you have set UITableViewDataSource in your .h file 当然,这假设您已在.h文件中设置了UITableViewDataSource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM