在我的A班。我正在使用Enum。
typedef enum {
EditProfile,
CreateProfile,
} AdressState;
@interface ManageAddress : UIViewController<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
{
AdressState state;
}
并在.m文件中分配值
-(IBAction)adress:(id)sender
{
state = CreateProfile;
MyAddress *my = [[MyAddress alloc]initWithNibName:@"MyAddress" bundle:nil];
[self.navigationController pushViewController:my animated:YES];
}
在我的MyAddressController
我正在访问枚举值
@interface MyAddress : UIViewController<UITextFieldDelegate,UITextViewDelegate>
{
AdressState state;
}
.m文件
if (state == EditProfile )
{
mobile.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"mobile"];
}
我的状态显示始终为EditProfile但我分配了一个值CreateProfile。请帮忙。
答案 0 :(得分:1)
您需要将ManageAddress
的{{1}}成员变量中的值分配给state
MyAddress
成员变量的值,因为它们是两个都在不同的班级。只需将您的state
方法更新为以下内容:
(IBAction)adress:(id)sender
}
答案 1 :(得分:0)
在AppDelegate或Singleton类中全局创建enum
,然后从ManageAddress
分配当前状态并在MyAddress
上获取
在这里分配:
-(IBAction)adress:(id)sender {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.state = CreateProfile;
MyAddress *my =[[MyAddress alloc]initWithNibName:@"MyAddress" bundle:nil];
[self.navigationController pushViewController:my animated:YES];
}
来到这里:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.state == EditProfile ) {
mobile.text =[[NSUserDefaults standardUserDefaults]objectForKey:@"mobile"];
}