UITableView showing more rows than specified in numberOfRowsInSection:

后端 未结 9 1085
谎友^
谎友^ 2021-02-01 03:32

I want my tableView to show 6 rows with text in it, in this case \"Example.\" As far as I can tell, I have my numberOfSectionsInTableView: and numberOfRowsIn

相关标签:
9条回答
  • 2021-02-01 03:35

    This is Because of Your Table-view Height. Weather you have Write

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    

    // Return the number of rows in the section. return 6; }

    But its show rows According to Table-view Size. If you Dont want to show This extra Lines then Make UITableView Style Plain To Grouped.

    0 讨论(0)
  • 2021-02-01 03:43

    To programmatically remove it, use this: [yourTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    0 讨论(0)
  • 2021-02-01 03:46

    You could do something along the lines of:

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:7 inSection:0];
    [self.mytableView cellForRowAtIndexPath:indexPath].hidden = YES;
    

    Im sure there are some better ways but this is the first thing that came to mind.

    0 讨论(0)
  • 2021-02-01 03:52

    Swift Version

    The easiest method is to set the tableFooterView property:

    override func viewDidLoad() {
        super.viewDidLoad()
        // This will remove extra separators from tableview
        self.tableView.tableFooterView = UIView(frame: CGRect.zero)
    }
    
    0 讨论(0)
  • 2021-02-01 03:53

    If you're referring to the light gray lines that appear below the last row, that's simply the default way a UITableView draws the row separator.

    You could try changing the Separator style in Interface Builder (see the images below) to see if one of those might be more to your liking.

    enter image description here enter image description here

    0 讨论(0)
  • 2021-02-01 03:54

    You didn't say what you do want to see past the last row. If you just want to see the window background, then just embed your table view in a UIView that's just tall enough to show the number of rows you want to see. If you want to see more rows without scrolling, then you would have to adjust the size of that containing view based on the number of rows.

    0 讨论(0)
提交回复
热议问题