2010-05-15 64 views
2

我已經在.h文件中聲明瞭UITableView。我在表視圖5部分,現在我需要設置tableview.editing =只爲第4節如何設置編輯是在iPhone的特定部分是的

我怎麼能顯示部分4旁邊的+按鈕,並有所有其他部分的編輯= NO?

myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,320,415) style:UITableViewStyleGrouped]; 
     myTableView.delegate = self; 
     myTableView.dataSource=self; 
     [myTableView setSectionFooterHeight:0]; 
     [myTableView setSectionHeaderHeight:15]; 
     [myTableView setSeparatorColor:[UIColor lightGrayColor]]; 
     myTableView.backgroundColor = [UIColor colorWithRed:0.85546875 green:0.8828125 blue:0.92578125 alpha:1]; 
     [myView addSubview: myTableView]; 


I tried like this it is not working. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if(section==0) 
    { 
     myTableView.editing = NO; 
     myTableView.allowsSelectionDuringEditing = NO; 
     return 3; 
    } 
    else if(section ==1) 
    { 
     myTableView.editing = NO; 
     myTableView.allowsSelectionDuringEditing = NO; 
     return 2; 
    } 
    else if(section==4) 
    { 
     myTableView.editing = YES; 
     myTableView.allowsSelectionDuringEditing = YES; 
     if(isEdit == YES) 
     { 
      if([editObject.contactList count]>0) 
      { 
       return [editObject.contactList count]+1; 
      } 
      else 
      { 
       return 1; 
      } 
     } 
     else if(isEdit == NO) 
     { 
      if([addContactList count]>0) 
      { 
       return [addContactList count]+1; 
      } 
      else 
      { 
       return 1; 
      } 
     } 

    } 
    else if(section==2) 
    { 
     myTableView.editing = NO; 
     myTableView.allowsSelectionDuringEditing = NO; 
     return 1; 
    } 
    else if(section==3) 
    { 
     myTableView.editing = NO; 
     myTableView.allowsSelectionDuringEditing = NO; 
     return 1; 
    } 
    return 0; 
} 

我得到的第4節的+按鈕,但所有其他部分被移動到右側。

回答

2

實施

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

非常感謝你 – 2010-05-19 12:15:10

+0

這是很明顯的,但也確保你已將allowedSelectionDuringEditing屬性設置爲true。您可以在代碼或xib設計器中執行此操作。 更多詳細信息,請訪問:http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#jumpTo_4 – Helephant 2010-06-01 18:30:35

0

執行- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath,並返回UITableViewCellEditingStyleNone您不希望被編輯的部分中的行。

+0

+圖標是不是需要別人科,只需要對特定部分和其行。 – 2010-05-15 07:45:28

相關問題