2016-11-28 42 views
0

我有兩個類的類甲& B,在A類我有MapView類和一個按鈕上點擊該按鈕i要加載類B的的tableView在地圖上和我還需要在類A中設置B類TableView的框架A 所有內容都是在不使用故事板的情況下編寫的。請提前幫助我。如何加載在第一類視圖所述第二類的tableView數據

在類的viewDidLoad一個

-(void)viewDidload{ 
    [mapView addSubview:classBViewController.tableView]; 
    classBViewController.tableView.hidden=YES; 
} 

-(IBAction)buttonClick{ 
    classBViewController.tableView.hidden=NO; 
} 
+0

你爲什麼不乾脆引導到B級的視圖按鈕上點擊?通過使用Segue或PushViewController? –

+0

它非常老的項目,所以我們沒有使用任何故事板每一件事都以編程方式完成 – vardhan

回答

0

您可以通過委託或NSNotification做到這一點。

這裏,代表正在better.you可以通過以下更改使用委託。

在課堂A.H,做以下操作: -

@protocol ClassADelegate <NSObject> 

- (void)classAButtonClickEvent; 
@end 

,並委託對象ClassADelegate A類 @屬性(非原子,強)ID *代表;

在課堂上午

- (IBAction)buttonClick{ 
if ([delegate respondsToSelector:@selector(classAButtonClickEvent)]) { 
      [delegate classAButtonClickEvent]; 

} 

而在B類符合的ClassADelegate和實施classAButtonClickEvent()protocol.in你可以在你的classB.for前的tableview中進行的更改方法的方法

- (void)classAButtonClickEvent { 
    classBViewController.tableView.hidden=NO; 
} 

希望這有助於!

0

我不認爲Tanvi的答案就是你要找的。在這種情況下創建一個委託是沒有意義的,因爲你已經知道按鈕被點擊的時間(IBAction,buttonClick,當按鈕被點擊時應該觸發,因爲你已經正確設置了它)。

而是隱藏和取消隱藏在的tableview,你應該推B級到一個UINavigationController。您也不需要使用此解決方案將類B中的tableView添加爲viewDidLoad上mapView的子視圖。

下面是我在說什麼的例子:

// If you don't already have a navigation controller 
-(IBAction)buttonClick { 
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self]; 
    ClassB *classBViewController = [[ClassB alloc] init]; 
    [nav pushViewController:classBViewController animated:YES]; 
}  

// If you already have a navigation controller 
-(IBAction)buttonClick { 
    ClassB *classBViewController = [[ClassB alloc] init]; 
    [self.navigationController pushViewController:classBViewController animated:YES]; 
} 
相關問題