Jak usunąć puste komórki w UITableView? [duplikat]
To pytanie ma już odpowiedź tutaj:
- wyeliminuj dodatkowe separatory poniżej UITableView 31 odpowiedzi
Próbuję wyświetlić prosty UITableView
z niektórymi danymi. Chcę ustawić statyczną Wysokość UITableView
, aby nie wyświetlała pustych komórek na końcu tabeli. jak mam to zrobić?
Kod:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%d", [arr count]);
return [arr count];
}
11 answers
Ustaw widok stopki tabeli o zerowej wysokości (być może w metodzie viewDidLoad
), tak:
Swift:
tableView.tableFooterView = UIView()
Objective-C:
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Ponieważ tabela uważa, że istnieje Stopka do pokazania, nie wyświetla żadnych komórek poza tymi, o które wyraźnie prosiłeś.
Interface builder pro-tip:
Jeśli używasz xib/Storyboard , możesz po prostu przeciągnąć UIView (z wysokością 0PT) na dół widoku UITableView.
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-08-27 23:09:17
Swift 3 składnia:
tableView.tableFooterView = UIView(frame: .zero)
Składnia Swift:
tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
Swift 2.0 składnia:
tableView.tableFooterView = UIView(frame: CGRect.zero)
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-02-11 11:57:02
W Storyboardzie wybierz UITableView
i zmodyfikuj styl właściwości z Plain
na Grouped
.
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-04-18 10:17:39
Zaimplementowane z swift na Xcode 6.1
self.tableView.tableFooterView = UIView(frame: CGRectZero)
self.tableView.tableFooterView?.hidden = true
Druga linia kodu nie powoduje żadnego wpływu na prezentację, możesz użyć do sprawdzenia, czy jest ukryta, czy nie.
ODPOWIEDŹ zaczerpnięta z tego linku nie udało się ukryć pustych komórek w UITableView Swift
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 11:54:41
nie mogę dodać komentarza, więc dodaję to jako odpowiedź.
@Andy ' s answer is good and the same results can be achieved with the following line of code:
tableView.tableFooterView = [UIView new];
' new ' metoda należy do klasy NSObject i wywołuje metody alloc i INIT dla UIView.
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-31 12:24:32
Próbowałem kodu:
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
W sekcji viewDidLoad i xcode6 wyświetliło Ostrzeżenie. Umieściłem "ja"."przed nim i teraz działa dobrze. więc kod roboczy, którego używam to:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
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-26 13:29:27
Lub możesz wywołać metodę tableView, aby Ustawić Wysokość stopki w 1 punkcie, a ona doda ostatnią linię, ale możesz ją też ukryć, ustawiając kolor tła stopki.
Kod:
func tableView(tableView: UITableView,heightForFooterInSection section: Int) -> CGFloat {
return 1
}
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
2016-02-29 10:05:56
Za pomocą UITableViewController
Przyjęte rozwiązanie zmieni wysokość TableViewCell
. Aby to naprawić, wykonaj następujące kroki:
-
Wpisz poniższy fragment kodu w metodzie
ViewDidLoad
.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
-
Dodaj następującą metodę w pliku
TableViewClass.m
.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return (cell height set on storyboard); }
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-12-08 12:59:58
override func viewWillAppear(animated: Bool) {
self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
/// OR
self.tableView.tableFooterView = UIView()
}
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
2016-01-05 09:24:57
W poniższej metodzie:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (([array count]*65) > [UIScreen mainScreen].bounds.size.height - 66)
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [array count]*65));
}
else
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 66);
}
return [array count];
}
Tutaj 65 to wysokość komórki, a 66 to wysokość paska nawigacyjnego w UIViewController.
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
2016-11-28 07:50:11
In viewDidLoad:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
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
2016-01-08 07:03:58