我有一個叫做HomeViewController
的ViewController。它的子視圖是(UIView)。 ActivityView的子視圖是ActivityCard
(UIView)。在ActivityCard中,我有一個名爲Enter的按鈕。在它的點擊我需要將所有文本域的值從ActivityCard xib發送到HomeViewController並從那裏調用一個API。我以前從未與xib合作過,因此無法管理這種情況。任何幫助將不勝感激!發送按鈕上的值點擊從UIView到它的超級視圖的超級視圖(UIViewController)-iOS
編輯:
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此代碼已被寫入。
的方法在某種程度上是沒有得到所謂的創建方法。任何我可能會缺少的東西? – Dia
當我嘗試將標籤文本從HomeViewController設置爲ActivityCard時,它沒有正確設置值。我試過了:[_viewActivity.card.lblActivityCount setText:@「11」]; – Dia
正如我所見,你做對了。你能告訴我你是如何實施它們的嗎? @Dia – trungduc