싱글 톤 클래스를 사용하여 NSMutableArray를 뷰로 전송합니다.NSMutableArray에서 요소의 중복 된 출력 방지
문제점은 배열이 여러 번 표시된다는 것입니다.
지금은 세 개의 UITextField로 작업하고 있습니다. 각각은 배열에 추가되고 특정 형식으로 출력됩니다.
A/B
C
A/B
C
A/B
C
모든 I : 여기 내 출력처럼 보이는 것입니다 필요 표시 :
01 23,516,A/B
C
다음누군가가 나 누락 또는 재 작업 할 필요가 있는지 찾을 수 있다면 내 코드는 다음과 같습니다
UILabel * myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
[myLabel setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
myLabel.numberOfLines = 0;
NSMutableString * string = [NSMutableString string];
Education * myEducation = [Education sharedEducation];
for (Education * output in myEducation.educationOutputArray)
{
[string appendString:[NSString stringWithFormat:@"%@/%@ \n%@\n", [myEducation.educationOutputArray objectAtIndex:0], [myEducation.educationOutputArray objectAtIndex:1], [myEducation.educationOutputArray objectAtIndex:2], nil]];
}
myLabel.text = string;
[self.view addSubview:myLabel];
:
텍스트를 표시하려면 텍스트를 저장하는 곳입니다 :
-(void)saveButtonTapped:(id)sender
{
[_educationArray addObject:_aTextField.text];
[_educationArray addObject:_bTextField.text];
[_educationArray addObject:_cTextField.text];
Education * myEducation = [Education sharedEducation];
myEducation.educationOutputArray = _educationArray;
[self.navigationController popViewControllerAnimated:YES];
}
EDIT *
사용자가 텍스트 필드에 텍스트를 입력 할 때 동일한 세 개의 텍스트 필드를 사용하여 새로운 텍스트 세트를 추가 할 수도 있습니다.
for 루프를 제거한 경우 처음 만 표시됩니다. 모든 텍스트를 표시하려면 어떻게합니까? 이 오류에
[string appendString:[NSString stringWithFormat:@"%@/%@ \n%@\n", [output major], [output university], [output timeAtSchool]]];
결과 : 당신은 배열의 중복이없는
2012-12-29 17:03:07.928 EasyTable[14501:c07] -[__NSCFString major]: unrecognized selector sent to instance 0x7176850
2012-12-29 17:03:07.941 EasyTable[14501:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString major]: unrecognized selector sent to instance 0x7176850'
*** First throw call stack:
(0x1c99012 0x10d6e7e 0x1d244bd 0x1c88bbc 0x1c8894e 0x6162 0xff817 0xff882 0xffb2a 0x116ef5 0x116fdb 0x117286 0x117381 0x117eab 0x1184a3 0x118098 0x2c10 0x10ea705 0x21920 0x218b8 0xe2671 0xe2bcf 0xe1d38 0x2e5213 0x1c61afe 0x1c61a3d 0x1c3f7c2 0x1c3ef44 0x1c3ee1b 0x1bf37e3 0x1bf3668 0x1e65c 0x240d 0x2335 0x1)
libc++abi.dylib: terminate called throwing an exception
배열에 개체를 추가하는 방법과 관련이 있습니다. 코드를 추가 할 수 있습니까? – wattson12
가능한 경우 앱의 스크린 샷이 도움이 될 수 있습니다. 자신이 너무 어렵게 만들 수도 있습니다. –