2010-11-22 47 views
2

我没有使用NIB在我的应用程序上获得了UITableView。但是,因为我这样做,我无法获得通常与常规UITableView关联的编辑属性。例如,如果我使用@interface TableViewController:UITableViewContoller并在导航栏上添加editButtonItem,则只要按下该按钮,删除和移动行就会自动包含在内。如何以编程方式调用UITableView的编辑属性

但是,没有任何工作在我的UITableView。请帮忙。

// in .h 
@interface TableViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource> 
{ 
UITableView *tView; 
NSMutableArray *aMutArray; 
} 



    // in .m 
    -(id)init 
    { 
    [super initWithNibName:nil bundle:nil]; 

    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]]; 
    [[self navigationItem] setTitle:@"ReorderingTableCell"]; 

    return self; 
    } 

    - (void)loadView 
    { 
    [super loadView]; 

    CGRect tableFrame = CGRectMake(0, 0, 320, 300); 
    tView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain]; 
    [[self tView] setDelegate:self]; 
    [[self tView] setDataSource:self]; 

    aMutArray = [[NSMutableArray alloc] initWithObjects:@"first", @"second", @"third", nil]; 

    [[self view] addSubview:tView]; 
    } 

,然后一堆的委托方法,如:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath, 
- (void)setEditing:(BOOL)flag animated:(BOOL)animated 

等等

我不想经历的委托方法的细节,因为我创建了一个新的项目与一个简单的UITableViewController,它的工作原理。

顺便说一下,当我运行代码时,我设置了断点并调用了委托方法,但没有任何反应。它不会给我单元格左侧的删除图标和右侧没有移动的单元格图标。什么都没发生。

非常感谢!

回答

5

您必须致电-[UITableView setEditing:animated:]才能使表格视图进出编辑模式。

+0

谢谢soooo多!!!! – okysabeni 2010-11-23 15:48:36