1

更改UITabBarController的第一个选项卡的视图如何将参数传递给UITabBarController的第一个选项卡,以便视图控制器根据参数显示内容?我尝试将UITabBarController设置为自定义类并在其中显示内容(我认为它将反映在第一个选项卡中),但内容刚刚在所有选项卡上显示。通过传递参数

+0

你管理来解决这个问题? – bashan

回答

0

如果我理解你的话,你需要使用委托人。

例如:

的.h文件中的一些方法,你必须

#import .... 

@class OtherView; 

@protocol OtherViewDelegate 

//your methods to pass parameter 
-(void)example:(int)i; 

@end 

@interface OtherView : UIViewController { 

} 

@property (nonatomic, assign) id<OtherView> delegate; // Don't forget to syntesize 

@end 

.m文件

你参数传递他

[delegate example:parameterName]; //in my example it will be some int 

诠释你第一个选项卡

h。文件

#import "OtherView.h" 

@interface FirstTab : UIViewController <OtherViewDelegate> { 

} 

m.file

-(void)viewDidLoad 
{ 
    //if it's storyboard view you should use another method 
    OtherView *oV = [[OtherView alloc] init]; 
    oV.delegate = self 
} 
//just repeat method from delegate 
-(void)example:(int)i 
{ 
    NSLog(@"My num: %d", i); 
}