【问题标题】:Change view of first tab of UITabBarController by passing parameter通过传递参数更改 UITabBarController 的第一个选项卡的视图
【发布时间】:2013-10-21 18:01:43
【问题描述】:
如何将参数传递给 UITabBarController 的第一个选项卡,以便视图控制器根据参数显示内容?我尝试将 UITabBarController 设置为自定义类并在那里显示内容(我认为它无论如何都会反映在第一个选项卡中),但内容最终会显示在所有选项卡中。
【问题讨论】:
标签:
ios
objective-c
uiviewcontroller
parameters
uitabbarcontroller
【解决方案1】:
如果我理解正确,您需要使用委托。
例如:
.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.文件
-(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);
}