2013-08-13 12 views
6

Chcę użyć opcji "przesuń do usunięcia" w moim projekcie.Przesuń, aby usunąć opcję w problemach z wyświetlaniem UITableView.

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row]; 
     NSLog(@"delete row %@",userData); 
    } 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return YES; 
} 

Używam tego kodu, ale daje on następujące wyniki, których nie chcę. enter image description here

Nie chcę tego lewego znaku minus na komórce. Chcę po prostu przesuń i pokaż przycisk usuwania. Ten sam kod, którego użyłem w moim poprzednim projekcie i działa dobrze (to jest tylko przesuń palcem, aby pokazać przycisk usuwania, bez znaku minus po lewej stronie)

Pomóż mi rozwiązać ten problem.

+0

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/shouldIndentWhileEditing – Kevin

+0

http://stackoverflow.com/questions/3020922/is-there-any-to-hide-delete-button-while-editing-uitableview – Rushabh

+0

Nadpisujesz poprawne metody UITableViewDelegate. Ale czy ustawiasz właściwość "edycji" swojego UITableView na "TAK" w dowolnym miejscu kodu? Jeśli tak, spowoduje to, że czerwone znaki minus będą widoczne. – hgwhittle

Odpowiedz

9

Nadpisujesz prawidłowe metody delegatów dla funkcji "przeciągnij, aby usunąć". Jeśli chodzi o znaki minus:

Ukryj minus tak:

self.yourTableView.editing = NO; 
//or simply remove this line of code altogether because this property is NO by default 

Pokaż minus tak:

self.yourTableView.editing = YES; 
1

Spróbuj tego:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 
0

Wygląda na to zwracają flagę tableView.editing na tak wiersze pojawiają się ze znakiem minus. spróbuj wyszukać self.tableView.editing = YES; i zmień go na NO lub po prostu skomentuj ten wiersz.

3

Najpierw utworzyć widok tabeli i ustawić delegata i źródło danych do sposobu.

self.contacts=[[UITable alloc]init]; 
    self.contacts.dataSource=self; 
    self.contacts.delegate=self; 
    self.contacts.userInteractionEnabled=YES; 
    //self.contacts.editing = YES; 
    [self.view addSubview:self.contacts]; 

A następnie zastąpić delegata i metody źródła danych, aby usunąć zastąpić następujące metody.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 

Na minus na lewym boku użytku self.contacts.editing = TAK; W moim przypadku nie chcę tego znaku minus, więc po prostu nie używaj tej właściwości lub ustaw self.contacts.editing = NIE;

Dziękuję hw731 za przypomnienie mi tej własności, zmarnowałem mój pół dnia na ten temat.

Powiązane problemy