从其他文件访问UINavigationController

时间:2013-07-11 11:59:54

标签: objective-c class uinavigationcontroller

!!!是的,这是一个noob问题,但是是的。

所以我在file1中创建了一个导航控制器,其中包含一个表视图。该表视图中的单元格是自定义单元格,具有不同的类和xib(file2)。在file2 xib上,我有一个按钮,单击该按钮时,应将视图推入导航控制器。

现在我不知道如何从file2引用到file1中创建的导航控制器。

编辑:通过在AppDelegate中设置导航控制器并创建共享委托来解决此问题,但如果我在file1中设置导航控制器该怎么办?

1 个答案:

答案 0 :(得分:0)

在这种情况下,我希望 file2 中有delegate

.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

然后在 file1 中创建CustomCell对象时,您需要将delegate设置为self

CustomCell *customCell = …
….
customCell.delegate = self;

file1

中实施CustomCellDelegate
- (void)buttonClicked
{ 
  // TODO: push using navigation controller code.
}

以上是委托模式。有关delegates的更多信息,请查看教程here

根据 MVC(模型视图控制器)模式视图的作用是仅显示数据及其控制器作业以推送或呈现另一个控制器。

希望这有帮助!

相关问题