2015-01-21 23 views
0

.H的iOS,NSString的属性困惑为的UITextField

@interface HuntProfileView : UIViewController 
@property (strong, nonatomic) NSString *huntgroupTitle; 
@property (strong, nonatomic) NSString *huntgroupId; 
@property (strong, nonatomic) NSArray *lines; 
@end 


的.m

@interface HuntProfileView() 
@property (weak, nonatomic) IBOutlet UITextField *huntgrouptitleText; 
@property HuntLineTable *childView; 
@end 

@implementation HuntProfileView 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSLog(@"huntgroupTitle %@", self.huntgroupTitle); 
    self.huntgrouptitleText.text = self.huntgroupTitle; 
} 


实例,分配&执行

viewController.huntgroupTitle = title;是正确的,或者至少title是预期的字符串。

的的NSLog在.m输出为:

2015-01-21 09:47:42.267 changeView[1108:16196] huntgroupTitle <UITextField: 0x7fa9a8fc8480; frame = (16 63; 568 30); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fa9a8fc9c70>> 
2015-01-21 09:47:42.267 changeView[1108:16196] -[UITextField rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7fa9a8fc8480 
2015-01-21 09:47:42.270 changeView[1108:16196] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7fa9a8fc8480' 

更新:
分配self.huntgroupTitle一个字符串( “你好,世界”)时,我能够得到成功执行。调试表明,在实例化时,输入字符串title以及viewController.huntgroupTitle被确认为正确的类型。

+1

你应该把在断点处“viewController.huntgroupTitle =称号;”并检查标题。如果这不起作用,则覆盖“huntgroupTitle”的设置程序,并在其中放置一个断点以检查它的分配时间。 – Aris 2015-01-21 10:05:05

+0

问题不在你的'ViewDidLoad'中,请检查在**中添加'rangeOfCharacterFromSet'的位置。m ** – 2015-01-21 10:05:51

+0

需要更多代码。这通常发生在您意外地将“NSString”类型的变量赋值给“UITextField”类型的变量时。 – avismara 2015-01-21 10:10:29

回答

1

在初始化HuntProfileView时,您必须将UITextField指定为huntgroupTitle。请检查。

我猜你可能会做这样的

HuntProfileView *huntV = [[HuntProfileView alloc] init]; 
huntV.huntgroupTitle = **some UITextField**; 

的东西,而不是它应该是

HuntProfileView *huntV = [[HuntProfileView alloc] init]; 
huntV.huntgroupTitle = someTextField.text; 

请检查。由于

+0

我不是,我唯一使用的问题已在上面发布。 – 2015-01-21 10:25:35

+0

请检查'title'的类型,而您做'viewController.huntgroupTitle = title;' – 2015-01-21 11:57:20

+0

我做过了,我在我的问题中提到过。这个问题已经解决了,请看我的答案。 – 2015-01-21 12:02:05

-1

的故事板的源文件有:

<connections> 
    <outlet property="huntgroupTitle" destination="wx0-NH-iGn" id="P9H-Oe-AEm"/> 
    <outlet property="huntgrouptitleText" destination="wx0-NH-iGn" id="Z1E-9e-lEn"/> 
</connections> 

卸下财产"huntgroupTitle"线解决了这个