Czy Mogę wymusić Widok UITableView, aby ukryć separator między pustymi komórkami? [duplikat]

To pytanie ma już odpowiedź tutaj:

Przy użyciu zwykłego stylu UITableView z wystarczająco dużą liczbą komórek, że UITableView nie może wyświetlić ich wszystkich bez przewijania, żadne separatory nie pojawiają się w pustej przestrzeni pod komórkami. Jeśli mam tylko kilka komórek puste miejsce pod nimi zawiera separatory.

Czy Jest jakiś sposób, aby wymusić UITableView usunięcie separatorów w pustej przestrzeni? Jeśli nie, będę musiał załadować niestandardowe tło z separatorem narysowanym dla każdej komórki, co utrudni dziedziczenie zachowania.

Znalazłem nieco podobne pytanie tutaj, ale nie mogę użyć zgrupowanego UITableView w mojej implementacji.

Author: Community, 2009-10-28

10 answers

Możesz osiągnąć to, co chcesz, definiując stopkę dla widoku tabeli. Zobacz tę odpowiedź, aby uzyskać więcej szczegółów: wyeliminuj dodatkowe separatory poniżej UITableView

 112
Author: Daniel Hepper,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:26:09

Dla iOS 7.* i iOS 6.1

Najprostszą metodą jest ustawienie właściwości tableFooterView:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    // This will remove extra separators from tableview
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}

Dla poprzednich wersji

Możesz dodać to do TableViewController (będzie to działać dla dowolnej liczby sekcji):

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     // This will create a "invisible" footer
     return 0.01f;
 }

I jeśli to nie wystarczy , Dodaj również następujący kod :

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{        
    return [UIView new];

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
 211
Author: J. Costa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-26 15:36:32

Dla Swift:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.tableFooterView = UIView()  // it's just 1 line, awesome!
}
 97
Author: Sebastian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-25 11:37:52

Korzystając z linku od Daniela, zrobiłem rozszerzenie, aby było bardziej użyteczne:

//UITableViewController+Ext.m
- (void)hideEmptySeparators
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    v.backgroundColor = [UIColor clearColor];
    [self.tableView setTableFooterView:v];
    [v release];
}

Po kilku testach, okazało się, że rozmiar może być 0 i to działa, jak również. Więc nie dodaje jakiegoś marginesu na końcu tabeli. Dzięki wkw za ten hack. Postanowiłem opublikować to tutaj, ponieważ nie lubię przekierowań.

 67
Author: Sauleil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-08 13:59:25

Swift Version

Najprostszą metodą jest ustawienie właściwości tableFooterView:

override func viewDidLoad() {
    super.viewDidLoad()
    // This will remove extra separators from tableview
    self.tableView.tableFooterView = UIView(frame: CGRectZero)
}
 21
Author: King-Wizard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-13 22:32:19

Dla Swift:

self.tableView.tableFooterView = UIView(frame: CGRectZero)
 10
Author: Segev,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-18 08:23:56

Jeśli używasz iOS 7 SDK, jest to bardzo proste.

Wystarczy dodać tę linię w metodzie viewDidLoad:

self.yourTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
 8
Author: Salmo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-10 13:35:19

Ustawienie tabeli separatorStyle Na UITableViewCellSeparatorStyleNone (w kodzie lub w IB) powinno załatwić sprawę.

 7
Author: duncanwilcox,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-28 11:32:17

Używam:

UIView *view = [[UIView alloc] init];
myTableView.tableFooterView = view;
[view release];

Robi to w viewDidLoad. Ale możesz ustawić go wszędzie.

 5
Author: Dare2Dream,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-26 22:01:36

Następujące zadziałało bardzo dobrze dla mnie na ten problem:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

CGRect frame = [self.view frame];
frame.size.height =  frame.size.height - (kTableRowHeight * numberOfRowsInTable);

UIView *footerView = [[UIView alloc] initWithFrame:frame];
return footerView; }

Gdzie kTableRowHeight to wysokość moich komórek wiersza, a numberOfRowsInTable to liczba wierszy, które miałem w tabeli.

Hope that helps,

Brenton.
 0
Author: Callaghan001,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-20 11:42:08