2015-01-21 26 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"線解決了這個