2011-09-06 43 views
0

即时通讯学习Obj-C和即时通讯治疗,使我的第一个“Hello world”文本的UITableView。启动iphone。 UITableView你好世界与编辑按钮失败

我的问题是我无法在屏幕右侧编辑按钮显示。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 
[[cell textLabel] setTextAlignment:(UITextAlignmentCenter)]; 
[email protected]"Hello World"; 
//[cell.textLabel setText:@"Hola2"]; 
return cell; 
} 

和:

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    self.navigationItem.rightBarButtonItem=self.editButtonItem; 
} 

我缺少的东西?

感谢您的帮助。

+0

这段代码没有问题,它工作正常。 – Ron

+0

如果你正在学习iPhone的开发,我强烈建议你[检查出来](http://stackoverflow.com/questions/7296695/beginning-iphone-development-in-xcode-4/7296894#7296894)。 – rjgonzo

回答

4
self.navigationItem.rightBarButtonItem=self.editButtonItem; 

这必须在viewDidLoad中

你是不是也设置行和部分是否正确?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return 1; 
} 
+0

哦,我的上帝,我觉得很愚蠢,我写错了方法,tyvm! –