从未调用iOS代理方法

时间:2015-08-25 14:57:24

标签: ios objective-c delegates protocols

我遇到的问题是我的委托方法从未被调用过。调用goBack函数,但closeShopDetailView不是。

我试图在HBShopDetailView按下按钮告诉HBShopsVC淡出HBShopDetailView子视图。我之前使用过类似的委托模式,没有任何问题,所以我不确定为什么这不起作用。我已经查看了有关此主题的其他问题,他们的解决方案也没有对我有用。

我感谢所有人的帮助!

HBShopDetailView.h

@protocol HBShopDetailDelegate <NSObject>
- (void)closeShopDetailView;
@end


@interface HBShopDetailView : UIView

@property (nonatomic, weak) id<HBShopDetailDelegate> delegate;
@property (nonatomic, strong) IBOutlet UILabel *name;
@property (nonatomic, strong) IBOutlet UILabel *address;
@property (nonatomic, strong) IBOutlet UIImageView *logo;

- (id)initWithShopInformation:(PFObject *)shopInfo;

@end

HBShopDetailView.m - 相关方法

- (IBAction)goBack:(id)sender
{
    id<HBShopDetailDelegate> strongDelegate = self.delegate;
    [strongDelegate closeShopDetailView];
}

HBShopsVC.h

@interface HBShopsVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate, HBShopDetailDelegate>

@end

HBShopsVC.m - 相关方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"touch on row %d", (unsigned)indexPath.row);

    self.shopDetailView = [[HBShopDetailView alloc] initWithShopInformation: self.filteredArray[indexPath.row]];
    self.shopDetailView.delegate = self;
    [self.view addSubview:self.shopDetailView];

    //Fade in the detailView
    self.shopDetailView.alpha = 0;
    [UIView animateWithDuration:0.5 animations:^{
        self.shopDetailView.alpha = 1;
    }];
}

- (void)closeShopDetailView
{
    NSLog(@"closedetailview");
    self.shopDetailView.alpha = 1;
    [UIView animateWithDuration:0.5 animations:^{
        self.shopDetailView.alpha = 0;
    }];
}

0 个答案:

没有答案