简体   繁体   English

如何将Tableview固定在屏幕上

[英]How I can Fixed Tableview to Screen

I added Tableview on xib file(you can see on image).tableview is loading well . 我在xib文件上添加了Tableview(您可以在图像上看到)。tableview加载得很好。 But last cell is out of screen so when I Swipe Up last index is showing. 但是最后一个单元格不在屏幕上,因此当我向上滑动时,显示最后一个索引。 When I get off my hand, last cell is not appear. 当我下手时,最后一个单元格不会出现。 I don't change any height of tableview . 我不改变任何tableview的高度。 Why not fixed to my screen ? 为什么不固定在我的屏幕上?

I am using reveal menu like facebook in this project : https://github.com/mikefrederick/MFSideMenu 我在这个项目中使用像Facebook这样的显示菜单: https : //github.com/mikefrederick/MFSideMenu

Also You can see problem on movie. 您也可以在电影上看到问题。

https://www.dropbox.com/s/usfwdhl5w9znkl6/IMG_0006.MOV https://www.dropbox.com/s/usfwdhl5w9znkl6/IMG_0006.MOV

电影:

viewcontroller.h viewcontroller.h

@property(nonatomic,retain)IBOutlet UITableView * tableview;

viewcontroller.m viewcontroller.m

-(void)viewDidAppear:(BOOL)animated
{
     self.tableview.backgroundColor=[UIColor colorWithRed:(28/255.0) green:(28/255.0) blue:(28/255.0) alpha:1];
     [self.tableview setSeparatorColor:[UIColor blackColor]];

}
- (void)viewDidLoad
{
    [super viewDidLoad];




    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

}
#pragma mark -
#pragma mark - UITableViewDataSource


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0)
    {
        return 5;
    }
    if (section==1)
    {
        return 3;
    }
    return 0;
}

- (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];
    }
    cell.textLabel.text =@"exampleCell";



    NSLog(@"cell.contentView.bounds.size.width %1.0f",cell.contentView.bounds.size.width);
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 1)
        return 40;
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   self.tableview.layer.cornerRadius = 10.0f;
    tableView.layer.borderWidth = 2.0;
    tableView.layer.borderColor = [UIColor redColor].CGColor;
    return 60;


}
#pragma mark UITableViewDelegate
- (void)tableView: (UITableView*)tableView
  willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{

    cell.backgroundColor =[UIColor colorWithRed:(41/255.0) green:(41/255.0) blue:(41/255.0) alpha:1];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        //for example [activityIndicator stopAnimating];

    }
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    [headerView setBackgroundColor:[UIColor colorWithRed:(112/255.0) green:(112/255.0) blue:(112/255.0) alpha:1]];
    UILabel *titleLabel = [ [UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 44)];

    titleLabel.text = @"MÜŞTERİ ALANI";

    titleLabel.textColor = [UIColor whiteColor];

    titleLabel.backgroundColor = [UIColor clearColor];

    [headerView addSubview:titleLabel];
    return headerView;
}

In your video, this menu appears to be a slide out menu, presumably using some third party slide out menu controller library. 在您的视频中,此菜单似乎是一个滑出菜单,大概使用了一些第三方滑出菜单控制器库。 So this view controller is contained within some container view from that. 因此,此视图控制器包含在此容器中。 It is possible that the slide out menu controller isn't properly sizing your view controller to fit its container view. 滑出菜单控制器可能无法正确调整视图控制器的大小以适应其容器视图。

One solution would be to check any example apps that come with the slide out controller you're using to see if they suffer from the bug and report this to the developer if it is the case. 一种解决方案是检查您正在使用的滑出控制器随附的所有示例应用程序,以查看它们是否受到错误的影响,并在这种情况下向开发人员报告。 This would be good because other developers would benefit from the improvements. 这会很好,因为其他开发人员将从这些改进中受益。 In fact it's possible the slide out controller you're using has fixed this bug with a newer version already that you don't have yet. 实际上,您正在使用的滑出控制器可能已使用尚未提供的较新版本修复了此错误。

Another solution, assuming there's an example app that doesn't suffer from this, is to see how it is adding its slide out menu and see if you're failing to do something that they're doing. 假设有一个示例应用程序不受此影响,另一种解决方案是查看它如何添加其滑出菜单,并查看您是否没有做他们正在做的事情。

Lastly, if there's no example app or you can't figure out why theirs is working differently, try adding the following to your view controller's viewDidAppear: method: 最后,如果没有示例应用程序,或者您无法弄清为什么它们的工作方式不同,请尝试将以下内容添加到视图控制器的viewDidAppear:方法:

self.view.frame = self.view.superview.bounds;

This assumes that the container view they create is properly sized. 这假定它们创建的容器视图的大小正确。

Your problem seems to be in your xib . 您的问题似乎出在您的xib中 You have to set the size of your View to " Freeform " then add autosizing constraints on your view like you did on your tableView. 您必须将View的大小设置为“ Freeform ”,然后像在tableView上一样在视图上添加自动调整大小约束。

自由形式

自动调整大小

first you should select the CELL, not the TABLE VIEW. 首先,您应该选择CELL,而不是TABLE VIEW。 Next, go to the attribute inspector and click the separator, and you should select the custom inserts. 接下来,转到属性检查器并单击分隔符,然后应选择自定义插入。 Lastly you can adjust the separator line according to your wish. 最后,您可以根据需要调整分隔线。 Hope this will help you and others. 希望这对您和其他人有帮助。 Thanks for the question too. 也谢谢你的问题。

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

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