问题:
当我删除注释斜杠 ( //
) 时,Xcode 在创建新 UITableViewController 类时自动注释掉的内置 editButtonItem 不起作用。不起作用我的意思是编辑按钮根本不出现。滑动单元格也不起作用。
尝试的解决方案:
我试图遵循已在其他 stackoverflow 线程上发布的各种解决方法,但无济于事。我发现的大多数帖子都谈到了编辑按钮不起作用的各个方面(例如,没有显示减号等),但我发现很少有帖子根本没有显示编辑按钮。
预感:
我有一种预感,它可能与 UITableViewController 未正确实现有关。我对面向对象编程和objective-c都很陌生,所以如果答案是非常基本的东西,我很抱歉——但是,嘿,这是学习过程的一部分。任何帮助深表感谢。
代码:
____.h
#import <UIKit/UIKit.h>
#import "IndividualRecipeViewController.h"
@class BrowsePrivateRecipeViewController;
@protocol BrowsePrivateRecipeViewControllerDelegate
- (void)browsePrivateRecipeViewControllerDidFinish:(BrowsePrivateRecipeViewController *)controller;
@end
@interface BrowsePrivateRecipeViewController : UITableViewController
@property (weak, nonatomic) id <BrowsePrivateRecipeViewControllerDelegate> delegate;
@property (assign, nonatomic) NSUInteger listLength;
@property (strong, nonatomic) NSDictionary *dictionaryOfRecipes;
@property (strong, nonatomic) NSMutableArray *arrayOfRecipeNames;
// ... methods
@end
____.m
@interface BrowsePrivateRecipeViewController ()
@end
@implementation BrowsePrivateRecipeViewController
@synthesize delegate = _delegate;
@synthesize listLength = _listLength;
@synthesize dictionaryOfRecipes = _dictionaryOfRecipes;
@synthesize arrayOfRecipeNames = _arrayOfRecipeNames;
- (void)viewDidLoad
{
// ... code here
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
// ... other methods
更新:
LINK TO SOURCE CODE
所以我决定将源代码发布到我的整个项目中。我在多个文件中遇到了这个问题,但如果我把它固定在一个文件中,我很确定其余的都会到位。
请关注文件
BrowsePrivateRecipeViewController.m/.h.
这是问题最直接的例子。再次感谢您的耐心和帮助。
真挚地,
杰森
最佳答案
首先,我绝对不会使用自定义按钮来编辑表格。没有必要仅仅因为已经内置了一个。
只需使用 UIViewController
小号 editButtonItem
.
如果您必须在按下按钮时执行其他操作,请覆盖 -setEditing:animated:
并调用super
第一的。
您上面提到的错误是因为您试图访问 navigationBar
小号 navigationItem
,不存在。您应该访问 View Controller 的 navigationItem
.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
关于objective-c - editButtonItem 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10392472/