2015-11-04 45 views
0

我已经使用MFSideMenu来显示我的菜单项。但我不知道为什么它在最后显示我黑线。从MFSideMenuController(右侧)删除黑色视图

如何去除黑色部分。

这是什么出现在

enter image description here

我已经使用https://github.com/mikefrederick/MFSideMenu整合MFSideMenu最终图像。

这是我的代码Sidemen

-(void) viewDidLoad 
{ 
[super viewDidLoad]; 

self.view.backgroundColor = CustomPinkColor; 
MenuArray =[NSArray arrayWithObjects:@"Knects",@"Settings",@"Share",@"About",nil]; 
//tableView.backgroundColor = CustomPinkColor; 
tableView.alwaysBounceVertical = NO; 
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 

}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section 
{ 
return MenuArray.count; 
    } 

    - (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.backgroundColor=CustomPinkColor; 
    cell.textLabel.textColor=[UIColor blackColor]; 
} 
cell.textLabel.text = [MenuArray objectAtIndex:indexPath.row]; 
return cell; 
    } 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 40; 
} 

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
    { 
UIView *colorView = [[UIView alloc]init]; 
colorView.backgroundColor = CustomPinkColor; 
return colorView; 
    } 

回答

2

这是自动布局问题,这样就可以解决这个问题:

第1步:添加此方法MFSideMenuContainerViewController控制器

- (void)layoutContraintsforLeftView:(UIView*)view adjestToContainer:(UIView*)container { 
    if(!view) { 
     return; 
    } 

    view.translatesAutoresizingMaskIntoConstraints = NO; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeTop 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeTop 
                 multiplier:1.0 
                  constant:0.0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeLeading 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeLeading 
                 multiplier:1.0 
                  constant:0.0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeTrailing 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeTrailing 
                 multiplier:1.0 
                  constant:0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeBottom 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeBottom 
                 multiplier:1.0 
                  constant:0.0]]; 
    [view layoutIfNeeded]; 
} 



- (void)layoutContraintsForRightView:(UIView*)view adjestToContainer:(UIView*)container { 
    if(!view) { 
     return; 
    } 

    view.translatesAutoresizingMaskIntoConstraints = NO; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeTop 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeTop 
                 multiplier:1.0 
                  constant:0.0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeLeading 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeLeading 
                 multiplier:1.0 
                  constant:50.0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeTrailing 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeTrailing 
                 multiplier:1.0 
                  constant:0.0]]; 

    [container addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeBottom 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:container 
                  attribute:NSLayoutAttributeBottom 
                 multiplier:1.0 
                  constant:0.0]]; 
    [view layoutIfNeeded]; 
} 

第2步:替换法- (void)setupMenuContainerView)

- (void)setupMenuContainerView { 
    if(self.menuContainerView.superview) return; 

    self.menuContainerView.frame = self.view.bounds; 
    self.menuContainerView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 

    [self.view insertSubview:menuContainerView atIndex:0]; 
    [self layoutContraintsforLeftView:menuContainerView adjestToContainer:self.view]; 


    if(self.leftMenuViewController && !self.leftMenuViewController.view.superview) { 
     [self.menuContainerView addSubview:self.leftMenuViewController.view]; 
     [self layoutContraintsforLeftView:self.leftMenuViewController.view adjestToContainer:menuContainerView]; 
    } 

    if(self.rightMenuViewController && !self.rightMenuViewController.view.superview) { 
     [self.menuContainerView addSubview:self.rightMenuViewController.view]; 
     [self layoutContraintsForRightView:self.rightMenuViewController.view adjestToContainer:menuContainerView]; 
    } 
} 

第3步:现在做..运行代码。 。编码愉快:) enter image description here

enter image description here

+0

这工作,但我的名单现在是不可见的@Sachin –

+0

我已经在这个代码库https://github.com/mikefrederick/MFSideMenu测试。它在那里工作.. – SachinVsSachin

+0

你在列表视图中使用自动布局吗? – SachinVsSachin