iOS,NSString属性混淆为UITextField

时间:2015-01-21 10:00:22

标签: ios objective-c

的.h

@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;
}


实例化,分配&执行

^{
    HuntProfileView *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"HUNTVIEW"];
    viewController.huntgroupId = huntId;
    viewController.huntgroupTitle = title;
    [self.navigationController pushViewController:viewController animated:YES];
 }

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

.m中的NSLog输出为:

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分配文字字符串(“hello,world”)时,我能够成功执行。调试表明,在实例化时,titleviewController.huntgroupTitle的输入字符串都被确认为正确的类型。

2 个答案:

答案 0 :(得分:1)

在初始化HuntProfileView时,您必须将UITextField分配给huntgroupTitle。请检查一下。

我猜你可能会做这样的事情

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

而应该是

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

请检查。感谢

答案 1 :(得分:-1)

Storyboard源文件包含:

<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"的行已解决此问题