ten.textValue = [[NSMutableString alloc]init];
ten.textValue = [NSMutableString stringWithString:textField.text];
두 번째 줄에서 충돌이 발생합니다.
ten.textValue is NSMutableString
.NSMutableString stringWithString 크래시
ten.textValue = [[NSMutableString alloc]init];
ten.textValue = [NSMutableString stringWithString:textField.text];
두 번째 줄에서 충돌이 발생합니다.
ten.textValue is NSMutableString
.NSMutableString stringWithString 크래시
ten.textValue = [[NSMutableString alloc]init];
을 만들면 소유 한 개체가 생성됩니다.
다음 줄에 문자열을 추가하려고하면 자동으로 다시 만들어진 문자열이 생성됩니다. 이것은 컴파일러를 혼란스럽게합니다. 컴파일러는 "정지 상태 -이 객체는 이미 소유 된 할당 된 객체입니다"라고보고합니다.
대신 :
if(ten.textValue)
{
ten.textValue = [NSMutableString stringWithString: textField.text]};
}
10이 초기화되지 않았습니다. – Nitish
UITextField
is nil
by default 및 [NSMutableString stringWithString:nil]
-nil
를 전달하는 text
속성이 충돌이 발생하기 때문에 아마이다. 할당하기 때문에, 그것은 어떤 목적을 제공하지 않습니다 -
[NSMutableString stringWithString: textField.text ? textField.text : @""]
당신은 또한 첫 번째 줄을 제거해야합니다
당신은 당신이이 같은 예를 들어, 복사 할 통과 할 때 text
이 nil
있지 않은지 확인해야합니다 할당 된 값이 즉시 덮어 쓰기됩니다.
위의 코드는 textFieldShouldReturn에 있으므로 텍스트 필드 텍스트는 nil이 아닙니다. 텍스트 필드 텍스트가 나타납니다. – Nitish
@Nitish 두 번째 줄을 바꾸려고 했습니까? 아직도 충돌을합니까? – dasblinkenlight
에 textField는 무엇입니까? – andershqst
UITextField입니다. – Nitish
왜 새로운'NSMutableString'을 단지 다음 줄에 덮어 쓰기 위해 할당합니까? – dasblinkenlight