Objective c 自定义委托方法用法
我试图在NSObject(MenuComponent)和UIViewController(fullVC)类之间使用自定义委托。委托在UIViewController中声明,因为UIViewController需要将数据(标题和url)发送到我的NSObject类 我的协议方法在UIViewController(FullVC)中 FullVC.h文件Objective c 自定义委托方法用法,objective-c,Objective C,我试图在NSObject(MenuComponent)和UIViewController(fullVC)类之间使用自定义委托。委托在UIViewController中声明,因为UIViewController需要将数据(标题和url)发送到我的NSObject类 我的协议方法在UIViewController(FullVC)中 FullVC.h文件 @class FullVC; @protocol MenuComponentDelegate <NSObject> -(void
@class FullVC;
@protocol MenuComponentDelegate <NSObject>
-(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString;
@end
@interface FullVC:UIViewController<UIScrollViewDelegate,UITextViewDelegate>
@property (nonatomic,assign) id delegate;
@end
我的shareToView方法是在我的NSObject类中实现的
MenuComponent.m
@interface MenuComponent() <MenuComponentDelegate>
@property (nonatomic, weak) NSString *titleToShare;
@property (nonatomic, weak) NSString *urlToShare;
@end
@implementation MenuComponent
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.nav_controller.topViewController isKindOfClass:[FullVC class]])
{
if (indexPath.row==0)
{
[(FullVC *)self.vav_controller.topViewController setDelegate:self];
NSLog(@“The value of title to share: %@“,titleToShare);
}
}
}
-(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString
{
NSLog(@"title string after passing is: %@", titleString);
NSLog(@"url string after passing is: %@", urlString);
}
@end
@interface MenuComponent()
@属性(非原子,弱)NSString*titleToShare;
@属性(非原子,弱)NSString*urlToShare;
@结束
@实现菜单组件
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
如果([self.nav_controller.topViewController是类:[FullVC类]])
{
if(indexPath.row==0)
{
[(FullVC*)self.vav_controller.topViewController setDelegate:self];
NSLog(@“股权价值:%@”,titleToShare);
}
}
}
-(void)shareToView:(NSString*)标题字符串inUrl:(NSString*)urlString
{
NSLog(@“传递后的标题字符串为:%@”,标题字符串);
NSLog(@“传递后的url字符串为:%@”,url字符串);
}
@结束
委派数据时遇到问题。我的shareToView方法似乎超出范围。我的NSLogs未打印。唯一的NSLog打印是显示titleToShare值的。但该值打印为Null
共享所有权的值:(空)
有人能帮我怎么调用委托方法吗,因为看起来控制器不在调用,而且不确定它是否在范围内?谢谢你在你的方法中设置一些断点,学习使用调试器…我确实使用了调试器,但它不会进入方法调用。所以我相信委托方法不在范围内,也不确定我如何才能确定很难识别。该方法似乎从未调用过。谢谢您的帮助。
@interface MenuComponent() <MenuComponentDelegate>
@property (nonatomic, weak) NSString *titleToShare;
@property (nonatomic, weak) NSString *urlToShare;
@end
@implementation MenuComponent
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.nav_controller.topViewController isKindOfClass:[FullVC class]])
{
if (indexPath.row==0)
{
[(FullVC *)self.vav_controller.topViewController setDelegate:self];
NSLog(@“The value of title to share: %@“,titleToShare);
}
}
}
-(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString
{
NSLog(@"title string after passing is: %@", titleString);
NSLog(@"url string after passing is: %@", urlString);
}
@end