objective-c - editButtonItem 未显示

标签 objective-c ios xcode uitableview

问题:
当我删除注释斜杠 ( // ) 时,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/

相关文章:

ios - NSXMLParser 访问字符串值错误

objective-c - 当数组没有任何内容时如何取出数组的第一个组件

php - 从 Objective-C 应用程序发送 base64 到 PHP 服务器

ios - Swift App Xib - 第二个 ViewController - 标签未显示 30 秒,但按钮等显示。我该如何解决?

iphone - 如何对 NSPredicate 过滤的 coreData 属性求和?

ios - UIScrollview 类似 View Controller 之间的转换

ios - 在 iOS 上从 GPS 获取时间

ios - Socket.io监听方法在一段时间或失去Internet连接后不监听

iphone - 防止 iPad 中的自动屏幕锁定

ios - Cocoapods 未完全向现有工作区项目添加新的 pod/依赖项