Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用笔尖上的按钮_Ios_Objective C - Fatal编程技术网

Ios 使用笔尖上的按钮

Ios 使用笔尖上的按钮,ios,objective-c,Ios,Objective C,我有个问题, 我有一个NIB,它就像一个带按钮的可重用视图,它是一个有其他视图的视图,其中一个视图中有一个按钮。 该按钮用于加载更多项目/行 我已经加载了NIB,并且在我的viewController中有了视图 当我想在我的viewController中使用该按钮,创建一个插座以便我可以使用他时,我的问题就开始了。我已经看到了大量其他问题,但看不到任何可以帮助我的东西 提前感谢。在这里,您可以将其用作委派的示例 在.h文件中 @protocol SwipeCellDelegate <NSO

我有个问题, 我有一个NIB,它就像一个带按钮的可重用视图,它是一个有其他视图的视图,其中一个视图中有一个按钮。 该按钮用于加载更多项目/行

我已经加载了NIB,并且在我的viewController中有了视图

当我想在我的viewController中使用该按钮,创建一个插座以便我可以使用他时,我的问题就开始了。我已经看到了大量其他问题,但看不到任何可以帮助我的东西


提前感谢。

在这里,您可以将其用作委派的示例 在.h文件中

@protocol SwipeCellDelegate <NSObject>
- (void) onShowMore;
@end

 @interface SwipeDealCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) id<SwipeCellDelegate> delegate

@end
}

在任何要使用按钮功能的视图控制器中

 SwipeDealCollectionViewCell * cell = (SwipeDealCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
cell.delegate = self;
您将能够像这样使用委托函数

- (void)onShowMore {
NSLog(@"ABC");
}
在ViewControll中:

@implementation ViewController ()
- (IBAction)buttonPressed:(id)sender {
    ..do what ever you want
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *view = [[NSBundle mainBundle] loadNibNamed:@"buttonView" owner:self options:nil][0];
    ..add subView
}

然后在nib中,您可以将按钮目标连接到nib文件的所有者。试试。

为什么不在自定义类中为该按钮创建一个委托,并在相应的视图控制器类中重写该委托。好的,你能解释一下我怎么做吗?通过这件事,我有点像个新手@RajanMaheshwariGo。你会对委托有一个想法,我刚刚试过,但我遇到了一个问题,当我点击按钮时,我如何执行代码@在viewcontroller中创建自定义视图的对象并重写委托方法时,RajanMaheshwarimake将委托作为自身。。
@implementation ViewController ()
- (IBAction)buttonPressed:(id)sender {
    ..do what ever you want
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *view = [[NSBundle mainBundle] loadNibNamed:@"buttonView" owner:self options:nil][0];
    ..add subView
}