Problem with UITextView
I have a strange problem with trying to pass a string from one viewcontroller to another view controller if the string originates from a UITextview instead of UITextfield. Both UITextview.text and UITextfield.text are of type NSString.
The following code takes either Textfield.text or Textview.text depending on the fieldType and puts it into a string called aString.
NSString *aString = [[NSString alloc] init];
if (fieldType == 3) {
aString = textView.text;
} else {
aString = textField.text;
}
When I examine aString on either cases, I can see that it has successfully assigned the text into aString.
I then pass the string to the other view controller using this code.
[delegate updateSite:aString :editedFieldKey :fieldType];
[self.navigationController popViewControllerAnimated:YES];
This works fine if aString originated from textfield.text but nothing happens except the view controller is popped if aString was from textview.text
This is the code that takes aString and does stuff with it, however it doesn't even execute the first line of code "NSLog(@"Ret开发者_运维技巧urned object: %@, field type:%@", aString,editedFieldKey);" if aString was from textview.text Any help will be appreciated.
-(void)updateSite:(NSString *)aString :(NSString *)editedFieldKey :(int)fieldType {
NSLog(@"Returned object: %@, field type:%@", aString,editedFieldKey);
switch (fieldType) {
case 0: //string
[aDiveSite setValue:aString forKey:editedFieldKey] ;
NSLog(@"String set %@",[aDiveSite valueForKey:editedFieldKey] );
break;
case 1: //int
[aDiveSite setValue:[NSNumber numberWithInt:aString.intValue] forKey:editedFieldKey];
NSLog(@"Integer set");
break;
case 2: //float
NSLog(@"Saving floating value");
[aDiveSite setValue:[NSNumber numberWithFloat:aString.floatValue] forKey:editedFieldKey];
NSLog(@"Float set");
break;
case 3: //Text view
[aDiveSite setValue:aString forKey:editedFieldKey];
NSLog(@"Textview text saved");
default:
break;
}
[self.tableView reloadData];
}
Uhm, sounds strange but I think your syntax is wrong:
[delegate updateSite:aString :editedFieldKey :fieldType];
should be
[delegate updateSite:aString editedFieldKey:fieldType];
and the method name:
-(void)updateSite:(NSString *)aString :(NSString *)editedFieldKey :(int)fieldType;
should be:
-(void)updateSite:(NSString *)aString (NSString *)editedFieldKey :(int)fieldType;
Can you try it?
This is what I've changed it to for editing textfield
[self.delegate editingViewController:self didTypeText:aString forKey:editedFieldKey forFieldType:fieldType];
and for textview I've created a separate controller that deals with it (and it works)
[self.delegate editTextViewController:self didEditText:textView.text forKey:editedFieldKey];
精彩评论