I'm not sure what is going on here but I'm unable pass a string into a view that is being pushed onto a NavigationController.
我不确定这里发生了什么,但我无法将字符串传递到正被推送到NavigationController的视图中。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
InventoryInquiryViewController *listViewController = (InventoryInquiryViewController *)[storyboard instantiateViewControllerWithIdentifier:@"InventoryList"];
[listViewController setItemBalanceRecords: self.itemBalanceRecords]; //this is an NSMutableArray and it works
[listViewController setItemNumber: @"Not Working!"]; //this is an NSString and it remains nil
[self.navigationController pushViewController:listViewController animated:YES];
So passing in the array is working as expected by trying to set a simple string property is failing even if I specify a string literal. I'm out of ideas on this one.
因此,即使我指定了一个字符串文字,尝试设置一个简单的字符串属性也会失败,因此传入数组正在按预期工作。我对这个问题缺乏想法。
Edit:
I've updated the code to remove the issue around description. The code was shortened as I'm trying to set a couple of string values. The revised code is still displaying the same behaviour.
我已更新代码以删除描述问题。代码缩短了,因为我正在尝试设置几个字符串值。修订后的代码仍然显示相同的行为。
Edit:
They are declared as properties like this:
它们被声明为如下属性:
@property (nonatomic, strong) NSArray *itemBalanceRecords;
@property (nonatomic, strong) NSString *itemNumber;
The application is for internal enterprise use and supports ios7 only.
该应用程序仅供内部企业使用,仅支持ios7。
2 个解决方案
#1
2
Try renaming the property from description to something else. Description is an NSObject
property (which is a superclass for UIViewController
) and having a property of the same name can cause weird behavior such as you describe.
尝试将属性从描述重命名为其他内容。 Description是一个NSObject属性(它是UIViewController的超类),并且具有相同名称的属性可能会导致奇怪的行为,如您所描述的。
#2
1
description is method for all NSObject's subclasses, so you shouldn't use it for your own needs https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/description
description是所有NSObject的子类的方法,所以你不应该将它用于你自己的需要https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html #// apple_ref / OCC / intfm / NSObject的/描述
#1
2
Try renaming the property from description to something else. Description is an NSObject
property (which is a superclass for UIViewController
) and having a property of the same name can cause weird behavior such as you describe.
尝试将属性从描述重命名为其他内容。 Description是一个NSObject属性(它是UIViewController的超类),并且具有相同名称的属性可能会导致奇怪的行为,如您所描述的。
#2
1
description is method for all NSObject's subclasses, so you shouldn't use it for your own needs https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/description
description是所有NSObject的子类的方法,所以你不应该将它用于你自己的需要https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html #// apple_ref / OCC / intfm / NSObject的/描述