iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – popover中的表视图不滚动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有下面的代码显示带有tableview的popover,它完美地运行.

tableview显示13个数字,我可以滚动并看到相同的但是当我在模拟器上发布鼠标触摸时它会回到顶部.

它不会停留在显示它的行,但会将我带回第1到第10行.

滚动后如何使其保持在位置.或者以下代码中的任何修复.

提前致谢.

- (IBACtion)btn:(id)sender {

    if([popoverController isPopoverVisible])
    {
        [popoverController dismissPopoverAnimated:YES];
        return;
    }
    //build our custom popover view
    UIViewController* popoverContent = [[UIViewController alloc]init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,320,680)];
    popoverView.BACkgroundColor = [UIColor blackColor];

    @R_696_10793@ers = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",nil];


    UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0,680)];
    tblViewMenu.delegate = self;
    tblViewMenu.datasource = self;
    tblViewMenu.rowHeight = 32;

    [popoverView addSubview:tblViewMenu];
    popoverContent.view = popoverView;
    popoverContent.contentSizeForViewInPopover = CGSizeMake(320,320);
    popoverController = [[UIPopoverController alloc]
                              initWithContentViewController:popoverContent];

    [popoverController  presentPopoverFromRect:self.btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}




- (NSInteger)@R_696_10793@erOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView @R_696_10793@erOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [@R_696_10793@ers count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier] ;
    }

    // Configure the cell...
    NSString *color = [@R_696_10793@ers objectATindex:indexPath.row];
    cell.textLabel.text = color;

    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath {
        NSString *@R_696_10793@er = [@R_696_10793@ers objectATindex:indexPath.row];

    NSLog(@"%@",@R_696_10793@er);

    [popoverController dismissPopoverAnimated:YES];

    }

我猜我需要更改以下值:

UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,680)];


    UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0,680)]];

如果我使用

UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,320)];

然后

UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0,320)]];

但是,当我向下滚动时,它会一直到达顶行.它不会停留在滚动到的同一行中.

解决方法

正确使用自动调整!

Popover – 具有内容大小

popoverView – 其初始大小应与popover的内容大小和使用相同
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

tblViewMenu-它的初始大小应该与它的祖先(popoverView)的大小相同,再次使用UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

您的表不滚动,因为它太大而不需要滚动.只有弹出窗口正在削减它.

CGSize contentSize = CGSizeMake(320,320);

UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,contentSize.width,contentSize.height)];
popoverView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:popoverView.bounds];
tblViewMenu.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

popoverContent.contentSizeForViewInPopover = contentSize;

大佬总结

以上是大佬教程为你收集整理的ios – popover中的表视图不滚动全部内容,希望文章能够帮你解决ios – popover中的表视图不滚动所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。