iphone - 启动iphone。带有编辑按钮的 UITableView Hello world 失败

标签 iphone ios ios4

我正在学习 Obj-C,并且打算用“Hello world”文本制作我的第一个 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)];
cell.textLabel.text=@"Hello World";
//[cell.textLabel setText:@"Hola2"];
return cell;
}

和:

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

我错过了什么吗?

感谢您的帮助。

最佳答案

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;
}

关于iphone - 启动iphone。带有编辑按钮的 UITableView Hello world 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7316168/

相关文章:

ios - 为什么我会因 dispatch_once 而陷入僵局?

iPhone 应用程序背景与 MPMusicPlayer

iphone - 如何表明代码需要被删除......最终

ios - 使用不同 viewCell 布局的最佳方式

ios webview流后台模式

ios - 基于 bool 值比较两个数组和匹配元素

objective-c - performSelectorOnMainThread 奇怪

ios - 我们可以在 Lion 上安装 xcode_3.2.5_and_ios_sdk_4.2_final 吗

iphone - JSON - iPhone SDK 上的框架错误

IOS - 使用 NSURLRequest 在 HTTP header 中进行 token 身份验证