2015-10-14 12 views
5

IF Name is present then it will look like thiscome nascondere titolo della sezione, se risultare non trovato utilizzando searchbar in iOS 8

IF Name is not present then it look like this i want to hide section title if name is not present

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 
{ 
    if (_segment.selectedSegmentIndex==0) 
    { 
     return sortedKeys; 
    } 
    else 
    { 
     return sortedKeys1; 
    } 
} 

Io uso questo codice, ma non voglio titolo della sezione se il nome non è presente, ora il suo give mE titoli delle sezioni

+1

Do si tenta di restituire 0 numero di sezione? – anhtu

+0

sì restituisco 0 in numberrowsinsection – Asmita

+0

Intendo in numberofsection, non numberrowsinsection. – anhtu

risposta

1

Se non ci sono le righe che impostare il titolo della sezione a zero.

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) 
{ 
       return nil; 
    } else { 
     return "section title \(section)" 
    } 
    return @""; 
} 

Questo funzionerà.

+0

grazie vijay il suo lavoro sei troppo grande – Asmita

+0

Benvenuto ... Codifica di coccole – vijay

0

Si dovrebbe usare sia questo uno restituire il numero corretto di sezioni:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; 

O questo ritorno CGFLOAT_MIN se non ci sono righe nella sezione corrispondente:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; 

Speranza che aiuta.

Tom

1

Prova ritorno 0 in numberOfSectionsInTableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    if (result_not_found) { /// pass the condition when "result not found" here 
     return 0; 
    } 

    if (_segment.selectedSegmentIndex==0) { 
     return ([sortedKeys count]); 
    } 
    else { 
     return ([sortedKeys1 count]); 
    } 
} 
+0

Prova questo, se lo stesso. Forse la risposta di @vijay è corretta. – anhtu

+0

sì anhtu, vijay ha ragione il suo lavoro grazie mille per il vostro aiuto – Asmita

+0

Si prega di segnare la risposta di @vijay è corretta. – anhtu

Problemi correlati