问题
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