나는 학교 프로젝트를위한 작은 컨버터 애플 리케이션, 애플 리케이션 스토어에 게시되지 않습니다 학교 학년을위한 애플 리케이션에 최선을 다하고 있습니다. 이 개발자가 어떻게 된 것인지 아는 사람이 있는지 궁금합니다. this app객관적인 C 변환기 애플
값을 변환하는 연결을 만들었습니까? 내가 상상할 수있는 가장 간단한 방법은 스위치의 경우 함께하지만 너무 많은 불필요한 코드를 만들 것입니다 : 응답에 대한
if (first column is distance) then if(second column is metres)
case0:third column is yards -> do something
case1:third column is kilometers ->do something
case2:third column is metros ->do nothing
등 ....
감사합니다. 빠른 답변
감사합니다, 이것은 내가 지금까지 아이폰 OS 시뮬레이터 이초가 첫 번째의 행에 따라 표시되는 올바르게 세 개의 열 선택기를 표시하고 만든 것입니다 : 편집
. 이게 다 좋다고 나에게 말할 수 있니? 복잡한 일이 아닌가?
#import "konverterViewController.h"
@interface konverterViewController ()
@end
@implementation konverterViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.fizVelicine = [[NSArray alloc] initWithObjects:@"distance",@"mass" , nil];
self.udaljenostJedinice = [[NSArray alloc] initWithObjects:@"meter", @"kilometer", @"yard", @"inch", nil];
self.masaJedinice = [[NSArray alloc] initWithObjects:@"kilogram",@"dekagram",@"gram",@"tone" , nil];
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *retval = (id)view;
if (!retval) {
retval = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f,
[pickerView rowSizeForComponent:component].width,
[pickerView rowSizeForComponent:component].height)];
}
retval.opaque = NO;
retval.backgroundColor = [UIColor orangeColor];
retval.adjustsFontSizeToFitWidth = YES;
retval.font = [UIFont systemFontOfSize:12];
if (component == 0) {
retval.textAlignment = NSTextAlignmentCenter;
retval.text = [self.fizVelicine objectAtIndex:row];
}
else if ([self.odabir isEqualToString:@"distance"]){
retval.textAlignment = NSTextAlignmentCenter;
retval.text = [self.udaljenostJedinice objectAtIndex:row];
}
else {
retval.textAlignment = NSTextAlignmentCenter;
retval.text = [self.masaJedinice objectAtIndex:row];
}
return retval;
}
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
if(component== 0)
{
return [self.fizVelicine count];
}
else
{
if([self.odabir isEqualToString:@"distance"]){ return [self.udaljenostJedinice count];}
else {return [self.masaJedinice count];}
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component == 0)
{
return [self.fizVelicine objectAtIndex:row];
}
else {
if([self.odabir isEqualToString:@"distance]){
return [self.udaljenostJedinice objectAtIndex:row];}
else {
return [self.masaJedinice objectAtIndex:row];
}
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component == 0) {
self.odabir=[[NSString alloc] initWithFormat:@"%@" , [self.fizVelicine objectAtIndex:row]];
[pickerView reloadAllComponents];}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
처음에는 깨닫지 만, 다중 분기 if-else-if는 특히 첫 번째 세그먼트가 더 많아 질수록 조금 어색합니다. – danh
고마워,하지만 내 주요 문제는 어떻게 변환 결과에 대한 데이터를 계산하는 데 사용할 수식을 알 수 있습니다. 어떻게 든 나는 어느 행이 1인지 알 필요가있다. 2. 계산을 위해 올바른 수식을 선택할 수 있도록 2.와 3. 열. 어쩌면 그렇게 할 생각이 있습니까? 예를 들어, 1. 행이 거리, 2.km와 3. 메트로 인 경우 올바른 결과를 얻으려면 첫 번째 값에 1000을 곱해야합니다. 어떤 작업을 사용할지 결정하는 가장 쉬운 방법은 무엇입니까? – user3194296
. 나는 내 대답을 고쳤다. – danh