我正在学习 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/