Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过点击带协议的滑出菜单过滤UITableView提要_Ios_Objective C_Uitableview_Delegates_Protocols - Fatal编程技术网

Ios 通过点击带协议的滑出菜单过滤UITableView提要

Ios 通过点击带协议的滑出菜单过滤UITableView提要,ios,objective-c,uitableview,delegates,protocols,Ios,Objective C,Uitableview,Delegates,Protocols,假设你有一个滑出菜单。当您在此滑出菜单中键入一个项目时,您希望使用该滑出菜单项中的NSString筛选出应用程序的提要,这是一个充满自定义单元格的UITableView 您认为正确的方法是使用协议和委托 // SlideOutMenuTableViewController.h #import <UIKit/UIKit.h> #import "SlideOutMenuItems.h" #import "SlideOutMenuCellTableViewCell.h" @proto

假设你有一个滑出菜单。当您在此滑出菜单中键入一个项目时,您希望使用该滑出菜单项中的NSString筛选出应用程序的提要,这是一个充满自定义单元格的UITableView

您认为正确的方法是使用协议和委托

//  SlideOutMenuTableViewController.h

#import <UIKit/UIKit.h>
#import "SlideOutMenuItems.h"
#import "SlideOutMenuCellTableViewCell.h"

@protocol filterFeed <NSObject>

-(void)filterFeedFromSlideOutItemTapped:(NSString   *)slideOutItemStringData; //String to pass slideOut menu item string back to feed
@end

@interface SlideOutMenuTableViewController : UITableViewController

@property(nonatomic,assign)id<filterFeed> stringDelegate;

@end
在滑出菜单视图控制器中,声明协议、关联方法(在提要视图控制器中实现)和委托

//  SlideOutMenuTableViewController.h

#import <UIKit/UIKit.h>
#import "SlideOutMenuItems.h"
#import "SlideOutMenuCellTableViewCell.h"

@protocol filterFeed <NSObject>

-(void)filterFeedFromSlideOutItemTapped:(NSString   *)slideOutItemStringData; //String to pass slideOut menu item string back to feed
@end

@interface SlideOutMenuTableViewController : UITableViewController

@property(nonatomic,assign)id<filterFeed> stringDelegate;

@end
您也要确保在后一个实现中合成您的委托:

@implementation SlideOutMenuTableViewController
@synthesize stringDelegate;
您启动了构建,它崩溃了,并显示以下错误消息:

2015-10-13 15:15:06.245 Flame[1607:479051] The NSString in the slide out menue item cell is Friend into
2015-10-13 15:15:06.245 Flame[1607:479051] The string of the tapped menu items is kind of class NSString
2015-10-13 15:15:06.245 Flame[1607:479051] The stringDelegate value prior to executing the delegate method is All Flames
2015-10-13 15:15:13.270 Flame[1607:479051] -[__NSCFConstantString filterFeedFromSlideOutItemTapped:]: unrecognized selector sent to instance 0x100306d10
2015-10-13 15:15:13.272 Flame[1607:479051] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString filterFeedFromSlideOutItemTapped:]: unrecognized selector sent to instance 0x100306d10'
*** First throw call stack:
(0x183e94f5c 0x19899bf80 0x183e9bc6c 0x183e98c14 0x183d9cdcc 0x1000e0d0c 0x189ad9c78 0x189ad9ae0 0x189ad9da8 0x18951dc6c 0x1895d8f8c 0x189694828 0x1896a0dc8 0x1893dd1c8 0x183e4bc30 0x183e499d4 0x183e49e04 0x183d78dc0 0x18eecc088 0x189452f44 0x1000e05ec 0x1991c68b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
你怎么能修好它

非常感谢您的帮助


谢谢

您应该注意的是:

-[__NSCFConstantString filterFeedFromSlideOutItemTapped:]: unrecognized selector sent to instance 0x100306d10
这表明您试图以字符串形式发送
filterFeedFromSlideOutItemTapped:
消息,这显然是行不通的

您没有显示将此委托属性设置为符合
filterFeed
协议的实例的位置,因此接下来需要查看该位置

更新:

要正确设置,这实际上取决于您是使用故事板还是用代码构建所有内容。如果要在代码中进行设置,则需要找到创建这两个控制器(可能是导航控制器或拆分视图控制器)的公共父级,并将代理设置在那里

如果使用故事板,可以在设计器中连接代理


如果这两个选项都失败,您可以让tableview进入视图控制器层次结构并找到滑出控制器,这样设置属性,但这并不理想。

Hi@Ben Scheirman:谢谢!由于我没有segue(我通常在那里设置协议委托,并且它可以工作),所以我正在努力设置委托的位置。在我试图弄明白一些事情的时候,我希望能得到更多的指导。正如你所知道的,我是一个创业者,自学成才,希望能让它成功,即使它并不漂亮!:)感谢您更新了您的回复,并提供了更多详细信息。这很有帮助。
-[__NSCFConstantString filterFeedFromSlideOutItemTapped:]: unrecognized selector sent to instance 0x100306d10