UITableView is getting a gap on top [closed]

泄露秘密 提交于 2019-12-03 15:57:31

问题


Iam not sure if it is the appropriate question to ask right now. I am working with Xcode 5 (preview version ) on the table view. The issue right now is if my table view is selected as group than I am having a gap between the first cell and the top edge of table.

The code for uitable view delegate is below

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"cell %d",indexPath.row];
    return cell;
}

Image below when I am choosing group in the xib

However, if i am switching to plain, table is normal

Any thoughts for this situation. I googled it but seems there are nothing out there. Any helps are welcomed here.


回答1:


That is the expected appearance of a grouped table view in iOS 7. If you open the Settings app you will see a similar separator bar at the top of the table and in between each section in the table view (grey in color).




回答2:


For the sake of being thorough you should implement the number of sections in the table view and in this case, return one. Its possible that theres a bug with Xcode 5 wherein if you do not implement that method it provides you with an incorrect header.

If that does that not solve the issue I would recommend implementing

- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section

That may do the trick as well.



来源:https://stackoverflow.com/questions/17679052/uitableview-is-getting-a-gap-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!