2012-03-22 17 views
8

Domyślna wysokość jest zbyt duże dla mnie. Jak zmienić wysokość między dwiema sekcjami?Jak zmienić wysokość MIĘDZY sekcjami w GROUPED UITableView?

============================================== ==============================

Przepraszam za mój biedny angielski ... Mam na myśli lukę między dwiema sekcjami jest za duży. Jak to zmienić?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f); 
    UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease]; 
    view.backgroundColor = [UIColor blueColor]; 
    return view; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f); 
    UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease]; 
    view.backgroundColor = [UIColor redColor]; 
    return view; 
} 

Zmieniłem widok nagłówka i stopkę każdej sekcji. A oto wynik: enter image description here

myślę, że może być min wysokość szczeliny, bo ustawić wysokość nagłówka i stopki do 2px, ale różnica między dwóch odcinków jest jeszcze tak duża.

+0

Twoje pytanie nie jest wcale jasne, czy chcesz zmniejszyć różnicę między dwiema sekcjami, czy zmienić wysokość jednej sekcji, podczas gdy druga ma ten sam rozmiar? –

+0

Przepraszam za mój biedny angielski. Mam na myśli lukę między dwiema sekcjami. –

Odpowiedz

14

Można użyć stopki poglądów pomiędzy każdym z odcinków i dać im wielkości przestrzeni pragnienie poprzez realizację następujących metod w swojej UITableView za delegata.

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

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

W pierwszej metodzie delegata można powrócić prosty instancję UIView, aw drugim można powrócić wysokość, że pogląd ten powinien być. Ta druga metoda delegatów powinna umożliwiać kontrolę luki między sekcjami.

+1

Tak, myślę, że istnieje minimalna odległość. Dziękuję :) –

+1

Właściwość tableFooterView nie odnosi się do stopki poglądów między sekcjami. –

+0

To prawda. TableFooterView jest widokiem umieszczonym na samym dole UITableView. Widoki stopek dla każdej sekcji mogą być dostarczone przez delegata za pomocą metody '- (UIView *) tableView: (UITableView *) tableView viewForFooterInSection: (NSInteger) section'. Zaktualizowałem odpowiedź za pomocą tej poprawki. Dzięki. –

4

wypróbować ten kod

self.tableView.rowHeight = 0; // in viewdidload 
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; // in viewdidload 

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    return 0.01f; 
} 

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 
    return <your header height>; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ 
    return [[UIView alloc] initWithFrame:CGRectZero]; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 
    return <your header view>; 
} 

a wersja Swift jest

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    return your footer view 
} 

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 

    return your footer view height 
} 

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 0.01 
} 

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
    return UIView.init(frame: CGRect.zero) 
} 
0

trzeba użyć metody heightForHeaderInSection definiowania przestrzeni pomiędzy nagłówek & tekstu komórki. Możesz go również zmienić w zależności od różnych sekcji np. na niektórych odcinkach może być konieczne, aby pokazać więcej dystansu & pod niektórzy, nie chcą pokazać lukę. Dla takiego przypadku można użyć

CGFLOAT_MIN który 0.000001f

. Podajemy przykład, w jaki sposób można wykorzystać inną sekcję o różnych wysokościach nagłówków:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    if (section == 0 || section == 2) 
    { 
     return 55.0; 
    } 
    else 
    { 
     return CGFLOAT_MIN; 
    } 
} 

Mam nadzieję, że ci to pomoże.

Powiązane problemy