代表未被调用
我有一个 UITableViewCell 子类,如下所示:
@class MyCell;
@protocol MyCellDelegate
- (void) viewController:(MyCell*)viewCon userId:(NSNumber*)uid andType:(NSString*)type;
@end
@interface MyCell : UITableViewCell <MHLazyTableImageCell>{
id <MyCellDelegate> delegate;
NSNumber * mid;
NSNumber * uid;
}
- (IBAction) star:(id) sender;
- (IBAction) reply:(id) sender;
- (IBAction) message:(id) sender;
- (void) showMenu;
@property (nonatomic, retain) id <ConvoreCellDelegate> delegate;
@property (nonatomic, retain) NSNumber * mid;
@property (nonatomic, retain) NSNumber * uid;
在 IBAction 中调用委托:
- (IBAction) star:(id) sender
{
[self.delegate viewController:self userId:mid andType:@"star"];
}
我有另一个 UIVewController 如下:
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UITableViewDelegate, UITableViewDataSource, UISplitViewControllerDelegate, RKObjectLoaderDelegate, MHLazyTableImagesDelegate, UITextViewDelegate, ConvoreCellDelegate> {
.......
}
在我放置的实现中:
- (void) viewController:(MyCell*)viewCon userId:(NSNumber*)uid andType:(NSString*)type
{
NSLog(@"DELEGATE IS CALLED");
if ([type isEqualToString:@"star"]){
NSLog(@"Message id is %@", uid);
} else if ([type isEqualToString:@"reply"]){
[message becomeFirstResponder];
message.text = @"@username";
} else if ([type isEqualToString:@"message"]){
}
}
但是它没有进入其中。它从不打印 DELEGATE IS CALLED。这是为什么?
I have subclass a UITableViewCell as follows:
@class MyCell;
@protocol MyCellDelegate
- (void) viewController:(MyCell*)viewCon userId:(NSNumber*)uid andType:(NSString*)type;
@end
@interface MyCell : UITableViewCell <MHLazyTableImageCell>{
id <MyCellDelegate> delegate;
NSNumber * mid;
NSNumber * uid;
}
- (IBAction) star:(id) sender;
- (IBAction) reply:(id) sender;
- (IBAction) message:(id) sender;
- (void) showMenu;
@property (nonatomic, retain) id <ConvoreCellDelegate> delegate;
@property (nonatomic, retain) NSNumber * mid;
@property (nonatomic, retain) NSNumber * uid;
the delegate is called in the IBAction:
- (IBAction) star:(id) sender
{
[self.delegate viewController:self userId:mid andType:@"star"];
}
I have another UIVewController as follows:
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UITableViewDelegate, UITableViewDataSource, UISplitViewControllerDelegate, RKObjectLoaderDelegate, MHLazyTableImagesDelegate, UITextViewDelegate, ConvoreCellDelegate> {
.......
}
and in the implementation I put:
- (void) viewController:(MyCell*)viewCon userId:(NSNumber*)uid andType:(NSString*)type
{
NSLog(@"DELEGATE IS CALLED");
if ([type isEqualToString:@"star"]){
NSLog(@"Message id is %@", uid);
} else if ([type isEqualToString:@"reply"]){
[message becomeFirstResponder];
message.text = @"@username";
} else if ([type isEqualToString:@"message"]){
}
}
However it is not getting inside this. It never prints DELEGATE IS CALLED. why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上是在创建 MyCell 后设置委托吗?
简单的检查方法是添加一个断点并查看委托引用是否为零(0x0)。
编辑:根据您下面的评论,很确定您从未设置委托。
创建单元格时,必须将委托对象传递给该单元格,以便它可以调用某些内容。否则,您只是向 nil 对象发送消息。
因此,假设您在表视图控制器中正常创建单元格:
Are you actually setting the delegate after creating
MyCell
?Easy way to check is add a breakpoint and see if the delegate reference is nil (0x0).
EDIT: Base on your comments below, pretty sure you are never setting the delegate.
When you create your cell, you have to pass in the delegate object to that cell so it has something to call. Otherwise, you are just sending a message to a nil object.
So, assuming you are creating your cells normally in the table view controller: