この場合、私はdelegate
in file2を好むでしょう。
.h ファイルは次のようになります。
#import <Foundation/Foundation.h>
@protocol CustomCellDelegate <NSObject>
- (void)buttonClicked;
@end
@interface CustomCell : UITableViewCell
@property (nonatomic, weak) id<CustomCellDelegate> delegate;
- (void)getImageWithCompletionHandler:(handler)completionBlock;
@end
そして、 file1CustomCell
にオブジェクトを作成するときに、 asを設定する必要があります。delegate
self
CustomCell *customCell = …
….
customCell.delegate = self;
CustomCellDelegate
in file1を実装する
- (void)buttonClicked
{
// TODO: push using navigation controller code.
}
上記は委任パターンです。詳細については、こちらdelegates
のチュートリアルをご覧ください
MVC (モデル ビュー コントローラー)によると、パターンビューの仕事はデータを表示することだけであり、コントローラーの仕事は他のコントローラーをプッシュまたは提示することです。
お役に立てれば!