If statement 在if语句中使用UIImage作为条件
我试图将变量从主视图控制器中的NSDictionary加载到详细视图控制器中 我试图使用主视图控制器中的图像来确定要在局部视图控制器中使用的变量 我的代码在主视图控制器中是这样的If statement 在if语句中使用UIImage作为条件,if-statement,uiimageview,nsdictionary,If Statement,Uiimageview,Nsdictionary,我试图将变量从主视图控制器中的NSDictionary加载到详细视图控制器中 我试图使用主视图控制器中的图像来确定要在局部视图控制器中使用的变量 我的代码在主视图控制器中是这样的 -(IBAction)pushView:(id) sender{ SomeDetailViewController *detailController = [[SomeDetailViewController alloc] init]; if ((self.imageView.image = [
-(IBAction)pushView:(id) sender{
SomeDetailViewController *detailController = [[SomeDetailViewController alloc] init];
if ((self.imageView.image = [UIImage imageNamed:@"0002.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"titleA", @"headerkey2",,nil];
detailController.mapDictionary = mapDictionary;
NSLog(@"%@", [myDictionary objectForKey:@"headerkey2"]);
}
else if((self.imageView.image = [UIImage imageNamed:@"0003.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"TitleB", @"headerkey2",,nil];
detailController.myDictionary = myDictionary;
NSLog(@"%@", [myDictionary objectForKey:@"headerkey2"]);
}
[self.navigationController pushViewController:detailController animated:YES];
}
然后在我的接收细节视图控制器中,我的代码是
-(void) viewDidLoad{
[super viewDidLoad];
self.title = [(NSMutableDictionary *)myDictionary objectForKey:@"headerkey2"];
}
不幸的是,这不起作用。无论发生什么,导航栏标题都会显示相同的内容
我可以使用UIImage作为条件吗
任何帮助都将不胜感激
我已经使用了resack,但似乎并不是在所有情况下都有效。出于某种原因,在if语句中使用“=”吗?如果不是,则使用“==”代替
文档说[UIImage ImageName]返回与指定图像关联的对象,这意味着它应该始终为同一图像返回同一对象,这样您就可以在条件下使用UIImage。@user1114881如果我的答案有效,请检查我的答案是否被接受?我会很感激的。