我有一个名为HomeViewController
的ViewController。它的子视图是ActivityView
(UIView)。 ActivityView的子视图是ActivityCard
(UIView)。在ActivityCard中,我有一个名为Enter的按钮。单击它我需要将所有文本字段的值从ActivityCard xib发送到HomeViewController并从那里调用API。我之前从未使用过xib,因此无法管理这种情况。非常感谢任何帮助!
编辑:
ActivityCard.h
@interface ActivityCard : UIView
- (IBAction)actionEnterClick:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *lblActivityCount;
@property (weak, nonatomic) IBOutlet UIButton *enterButton;
@end
ActivityView.h
@interface ActivityView : UIView
@property (strong) ActivityCard *card;
@property (weak, nonatomic) IBOutlet iCarousel *carousel;
@end
ActivityView.m
- (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
if (view == nil)
{
_card = (ActivityCard*) [[[NSBundle mainBundle] loadNibNamed:@"ActivityCard" owner:nil options:nil] objectAtIndex:0];
_card.frame = CGRectMake(0, 0, 280.0, 350.0);
_card.layer.cornerRadius = 10.0f;
view = _card;
}
return view;
}
HomeViewController.h
@interface HomeViewController : UIViewController
@property (strong) ActivityView *viewActivity;
@end
HomeViewController.m
_viewActivity = (ActivityView*) [[[NSBundle mainBundle] loadNibNamed:@"ActivityView" owner:nil options:nil] objectAtIndex:0];
_viewActivity.frame = CGRectMake(0.0f, 0.0f, _viewContainer.frame.size.width, _viewContainer.frame.size.height);
[_viewActivity updateActivityUI];
for (UIView *child in _viewContainer.subviews) {
[child removeFromSuperview];
}
[_viewContainer addSubview:_viewActivity];
[_viewActivity.card.enterButton addTarget:self action:@selector(enterButtonDidTouch) forControlEvents:UIControlEventTouchUpInside];
[_viewActivity.card.lblActivityCount setText:@"11"];
当我们需要在按钮点击时加载ActivityView时,已编写此代码。
答案 0 :(得分:1)
有很多方法可以做到,我会告诉你一种我觉得这是最简单的方法。
property
Enter Button
property
和ActivityCard.h
使用下面的代码在HomeViewController
Enter Button
添加操作。
[self.activityView.cardView enterButton addTarget:self action:@selector(enterButtonDidTouch) forControlEvents:UIControlEventTouchUpInside];
在HomeViewController.m
名称enterButtonDidTouch
- (void)enterButtonDidTouch {
NSString *textOfTextField1 = self.activityView.activityCard.textField1.text;
// With the same way you can get others text of text fields and use them
}