Objective-C (iOS) : 레이블의 텍스트를 수정할 수 없습니다.

사용자 2080985

현재 처음으로 iOS 앱을 작성 중이며 직접 또는 이전 질문에서 확인할 수없는 문제가 발생했습니다. 현재 두 개의 뷰가 있고 하나의 ViewController.m 파일에서 제어되는 앱이 있습니다. 첫 번째보기에서 백분율 버튼을 클릭 할 때 두 번째보기에있는 레이블의 텍스트를 변경하고 싶습니다.

나는 그들을 속성으로 아울렛을 생성하여 레이블을 수정하려고했습니다. 어떤 이유로 코드는 화면에 표시되지 않고 실행됩니다. 이 문제가 현재 설정 한 관계와 관련이 있는지 궁금하거나 레이블을 잘못 부르고 있는지 확실하지 않습니다. 누구든지 나를 도울 수 있다면 대단히 감사하겠습니다. (특히 printResults 메서드에서. 관심있는 사람이있는 경우 워크 플로가 어떻게 보이는지 볼 수있는 링크를 주석에 추가했습니다.)

요약 된 질문 버전 :

// Label I would like to change the text of (in a second view in the same controller)
@property (strong, nonatomic) IBOutlet UILabel *resultTitle;

- (void) printResults:(int) percent :(int) weightOnBar :(Weights*) weightObject{
   // How I am trying to modify the text in a method within the viewcontroller.m file
   [self.fortyFivePlateLabel setText: [NSString stringWithFormat:@"Test"]];
}

ViewController.m

#import "ViewController.h"
#import "Weights.h"

@interface ViewController ()

// Objects represent the text fields
@property (strong, nonatomic) IBOutlet UITextField *weightField;
@property (strong, nonatomic) IBOutlet UITextField *repsField;

// Objectsrepresent the percentage buttons below the fields
@property (strong, nonatomic) IBOutlet id nintyFiveResult;
@property (strong, nonatomic) IBOutlet id nintyResult;
@property (strong, nonatomic) IBOutlet id eightyFiveResult;
@property (strong, nonatomic) IBOutlet id eightyResult;
@property (strong, nonatomic) IBOutlet id seventyFiveResult;
@property (strong, nonatomic) IBOutlet id seventyResult;
@property (strong, nonatomic) IBOutlet id sixtyFiveResult;
@property (strong, nonatomic) IBOutlet id sixtyResult;

// Weight object used to perform the on bar calculation
@property (strong, nonatomic) Weights *weightObj;

// Labels represent the values on the second view
@property (strong, nonatomic) IBOutlet UILabel *resultTitle;
@property (strong, nonatomic) IBOutlet UILabel *fortyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *thirtyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *twentyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *tenPlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *fivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *twoFivePlateLabel;

@end

@implementation ViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.weightField.delegate = self;
    self.repsField.delegate = self;
    self.weightObj = [Weights getInstance];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return NO;
}

/* weightModified: This method is called when the weight field is modified.
   If the reps or weight value entered is equal to zero all of the percentage
   results will be changed to zero. If valid values are passed in both fields
   the percentages of weight will be calculated.
 */
- (IBAction)weightModified:(UITextField *)sender {

    NSLog(@"Weight Input Value: %@", sender.text);
    NSLog(@"Reps Input Value: %@", self.repsField.text);

    if([sender.text isEqualToString:@""] == false && [self.repsField.text isEqualToString:@""] == false){

        NSLog(@"Weight Modified in if statement.");

        // Gather reps and weight value
        int reps = 0;
        int weight = 0;
        weight = [sender.text intValue];
        reps = [self.repsField.text intValue];

        NSLog(@"Weight: %d", weight);
        NSLog(@"Reps: %d", reps);

        int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
        int nintyInt = [self oneRepMax :0.9 :reps :weight];
        int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
        int eightyInt = [self oneRepMax :0.8 :reps :weight];
        int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
        int seventyInt = [self oneRepMax :0.7 :reps :weight];
        int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
        int sixtyInt = [self oneRepMax :0.6 :reps :weight];

        NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyFiveInt];
        NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyInt];
        NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyFiveInt];
        NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyInt];
        NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyFiveInt];
        NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyInt];
        NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyFiveInt];
        NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyInt];

        [self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
        [self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
        [self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
        [self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
        [self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];

    }

    else{
        [self.nintyFiveResult setTitle:@"95%%: 0 lbs" forState:UIControlStateNormal];
        [self.nintyResult setTitle:@"90%%: 0 lbs" forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:@"85%%: 0 lbs" forState:UIControlStateNormal];
        [self.eightyResult setTitle:@"80%%: 0 lbs" forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:@"75%%: 0 lbs" forState:UIControlStateNormal];
        [self.seventyResult setTitle:@"70%%: 0 lbs" forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:@"65%%: 0 lbs" forState:UIControlStateNormal];
        [self.sixtyResult setTitle:@"60%%: 0 lbs" forState:UIControlStateNormal];
    }

}

/* repsModified: This method is called when the weight field is modified.
 If the reps or weight value entered is equal to zero all of the percentage
 results will be changed to zero. If valid values are passed in both fields
 the percentages of weight will be calculated.
 */
- (IBAction)repsModified:(UITextField *)sender {

    if([sender.text isEqualToString:@""] == false && [self.repsField.text isEqualToString:@""] == false){

        NSLog(@"Reps Modified in if statement.");

        // Gather reps and weight value
        int reps = 0;
        int weight = 0;
        weight = [self.weightField.text intValue];
        reps = [sender.text intValue];

        NSLog(@"Weight: %d", weight);
        NSLog(@"Reps: %d", reps);

        int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
        int nintyInt = [self oneRepMax :0.9 :reps :weight];
        int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
        int eightyInt = [self oneRepMax :0.8 :reps :weight];
        int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
        int seventyInt = [self oneRepMax :0.7 :reps :weight];
        int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
        int sixtyInt = [self oneRepMax :0.6 :reps :weight];

        NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyFiveInt];
        NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyInt];
        NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyFiveInt];
        NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyInt];
        NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyFiveInt];
        NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyInt];
        NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyFiveInt];
        NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyInt];

        [self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
        [self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
        [self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
        [self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
        [self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];
    }

    else{
        [self.nintyFiveResult setTitle:@"95%%: 0 lbs" forState:UIControlStateNormal];
        [self.nintyResult setTitle:@"90%%: 0 lbs" forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:@"85%%: 0 lbs" forState:UIControlStateNormal];
        [self.eightyResult setTitle:@"80%%: 0 lbs" forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:@"75%%: 0lbs" forState:UIControlStateNormal];
        [self.seventyResult setTitle:@"70%%: 0 lbs" forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:@"65%%: 0 lbs" forState:UIControlStateNormal];
        [self.sixtyResult setTitle:@"60%%: 0 lbs" forState:UIControlStateNormal];
    }
}

/* oneRepMax: This method is used to compute the one rep according to the values passed
   percent: represents the percentages displayed on the screen
   numReps: represents the number of reps in the reps field
   weightToLift: represents the number in the wieght field
   The method returns a float of the weight to be displayed on screen
 */
- (float)oneRepMax:(float) percent :(int) numReps :(int) weightToLift{

    float r = (float) numReps;
    float w = (float) weightToLift;
    float max = w*(1+(r/30));

    return percent*max;
}

/* printResults: This method is used to print the results of the weight on bar in thesecond UI View
   percent: represents the percentage of one rep max selected to put on the bar
   weightOnBar: represents the total weight to be computed into plates
   weightObject: used to compute the plate values
 */
- (void) printResults:(int) percent :(int) weightOnBar :(Weights*) weightObject{
    [self.resultTitle setText:[NSString stringWithFormat:@"%d%%: %d", percent, weightOnBar]];
    [self.weightObj setTotalWeight:weightOnBar];

    [self.fortyFivePlateLabel setText: [NSString stringWithFormat:@"Test"]];
    [self.thirtyFivePlateLabel setText: [NSString stringWithFormat:@"X %d", [self.weightObj getThirtyFives]]];
    [self.twentyFivePlateLabel setText: [NSString stringWithFormat:@"X %d", [self.weightObj getTwentyFives]]];
    [self.tenPlateLabel setText: [NSString stringWithFormat:@"X %d", [self.weightObj getTens]]];
    [self.fivePlateLabel setText: [NSString stringWithFormat:@"X %d", [self.weightObj getFives]]];
    [self.twoFivePlateLabel setText: [NSString stringWithFormat:@"X %d", [self.weightObj getTwoPointFives]]];
}

// Percentage Buttons

- (IBAction)clickNintyFive:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
    [self printResults: 95: nintyFiveInt: _weightObj];
}

- (IBAction)clickNinty:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.9 :reps :weight];
    [self printResults: 90: nintyFiveInt: _weightObj];
}

- (IBAction)clickEightyFive:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.85 :reps :weight];
    [self printResults: 85: nintyFiveInt: _weightObj];
}

- (IBAction)clickEighty:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.8 :reps :weight];
    [self printResults: 80: nintyFiveInt: _weightObj];
}

- (IBAction)clickSeventyFive:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.75 :reps :weight];
    [self printResults: 75: nintyFiveInt: _weightObj];
}

- (IBAction)clickSeventy:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.7 :reps :weight];
    [self printResults: 70: nintyFiveInt: _weightObj];
}

- (IBAction)clickSixtyFive:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.65 :reps :weight];
    [self printResults: 65: nintyFiveInt: _weightObj];
}

- (IBAction)clickSixty:(id)sender {
    int weight = [self.weightField.text intValue];
    int reps = [self.repsField.text intValue];
    int nintyFiveInt = [self oneRepMax :0.6 :reps :weight];
    [self printResults: 60: nintyFiveInt: _weightObj];
}

@end
델타 크럭스

속성을 UILabel에 연결하지 않은 것 같습니다.

@property선언 의 줄 번호 옆에 채워야 할 작은 회색 원이 있습니다. 그렇지 않은 경우 UILabel을 Interface Builder의 ViewController로 컨트롤 드래그 한 다음 resultTitle을 콘센트로 선택해야합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Objective-C ARC 멀티 스레딩 iOS 앱에서 특정 메모리 누수를 수정할 수 없습니다.

분류에서Dev

지정된 레이블 텍스트에서 사이트 프리즘 요소를 정의 할 수 없습니다.

분류에서Dev

VC ++ CMFCOutlookBar의 탭 레이블 텍스트를 변경할 수 없습니다.

분류에서Dev

jquery에서 레이블 텍스트를 설정할 수 없습니다.

분류에서Dev

Objective-C 오류에서 어레이를 연결할 수 없습니다.

분류에서Dev

셀 제목의 텍스트를 설정할 수 없습니다.

분류에서Dev

텍스트 뷰의 텍스트를 설정할 수 없습니다

분류에서Dev

C # 차트에서 사용자 지정 x 축 레이블의 텍스트 방향을 변경할 수 없습니다.

분류에서Dev

Unity UI는 레이블에서 텍스트를 가져올 수 있지만 설정할 수는 없습니다.

분류에서Dev

vue의 버튼 및 텍스트 레이블을 클릭 할 수 없습니다.

분류에서Dev

geocodeAddressString iOS Objective C를 사용하여 맵을 플롯하기 위해 배열을 반복 할 수 없습니다.

분류에서Dev

C ++에서 전역 변수를 정의 할 수 없습니다.

분류에서Dev

iOS는 UIButton의 backgroundImage를 설정할 수 없습니다.

분류에서Dev

Objective c의 한 클래스에서 다른 클래스로 변수 값을 전달할 수 없습니다.

분류에서Dev

C ++에서 클래스의 변수를 수정할 수 없습니다.

분류에서Dev

플렉스 테이블의 아이콘 아래에 텍스트를 가운데 정렬 할 수 없습니다.

분류에서Dev

고정 높이 div에서 텍스트를 정렬 할 수 없습니다.

분류에서Dev

Objective-C 파일에서 Swift 클래스의 변수에 액세스 할 수 없습니다.

분류에서Dev

TextFormField로 텍스트를 업데이트 할 수 없습니다.

분류에서Dev

Objective C는 iPhone에서 실행할 때 텍스트 파일을 읽을 수 없습니다.

분류에서Dev

C # WebSocketSharp 이벤트로 인해 레이블 텍스트와 같은 WPF 요소 콘텐츠를 변경할 수 없습니다.

분류에서Dev

Node의 const에 텍스트를 할당 할 수 없습니다.

분류에서Dev

SPARQL은 정적 텍스트로 두 개의 변수를 레이블과 바인딩 할 수 있습니까?

분류에서Dev

js, 클래스 텍스트의 텍스트를 변경할 수 없습니다.

분류에서Dev

추가하기 전에 JTextArea의 텍스트를 설정할 수 없습니다.

분류에서Dev

이미지 위에 텍스트를 제대로 정렬 할 수 없습니다.

분류에서Dev

C #에서 문자열의 텍스트를 바꿀 수 없습니다.

분류에서Dev

C의 텍스트 파일에서 구조를 읽을 수 없습니다.

분류에서Dev

Objective-C : 합성 변수에 액세스 할 수 없습니다.

Related 관련 기사

  1. 1

    Objective-C ARC 멀티 스레딩 iOS 앱에서 특정 메모리 누수를 수정할 수 없습니다.

  2. 2

    지정된 레이블 텍스트에서 사이트 프리즘 요소를 정의 할 수 없습니다.

  3. 3

    VC ++ CMFCOutlookBar의 탭 레이블 텍스트를 변경할 수 없습니다.

  4. 4

    jquery에서 레이블 텍스트를 설정할 수 없습니다.

  5. 5

    Objective-C 오류에서 어레이를 연결할 수 없습니다.

  6. 6

    셀 제목의 텍스트를 설정할 수 없습니다.

  7. 7

    텍스트 뷰의 텍스트를 설정할 수 없습니다

  8. 8

    C # 차트에서 사용자 지정 x 축 레이블의 텍스트 방향을 변경할 수 없습니다.

  9. 9

    Unity UI는 레이블에서 텍스트를 가져올 수 있지만 설정할 수는 없습니다.

  10. 10

    vue의 버튼 및 텍스트 레이블을 클릭 할 수 없습니다.

  11. 11

    geocodeAddressString iOS Objective C를 사용하여 맵을 플롯하기 위해 배열을 반복 할 수 없습니다.

  12. 12

    C ++에서 전역 변수를 정의 할 수 없습니다.

  13. 13

    iOS는 UIButton의 backgroundImage를 설정할 수 없습니다.

  14. 14

    Objective c의 한 클래스에서 다른 클래스로 변수 값을 전달할 수 없습니다.

  15. 15

    C ++에서 클래스의 변수를 수정할 수 없습니다.

  16. 16

    플렉스 테이블의 아이콘 아래에 텍스트를 가운데 정렬 할 수 없습니다.

  17. 17

    고정 높이 div에서 텍스트를 정렬 할 수 없습니다.

  18. 18

    Objective-C 파일에서 Swift 클래스의 변수에 액세스 할 수 없습니다.

  19. 19

    TextFormField로 텍스트를 업데이트 할 수 없습니다.

  20. 20

    Objective C는 iPhone에서 실행할 때 텍스트 파일을 읽을 수 없습니다.

  21. 21

    C # WebSocketSharp 이벤트로 인해 레이블 텍스트와 같은 WPF 요소 콘텐츠를 변경할 수 없습니다.

  22. 22

    Node의 const에 텍스트를 할당 할 수 없습니다.

  23. 23

    SPARQL은 정적 텍스트로 두 개의 변수를 레이블과 바인딩 할 수 있습니까?

  24. 24

    js, 클래스 텍스트의 텍스트를 변경할 수 없습니다.

  25. 25

    추가하기 전에 JTextArea의 텍스트를 설정할 수 없습니다.

  26. 26

    이미지 위에 텍스트를 제대로 정렬 할 수 없습니다.

  27. 27

    C #에서 문자열의 텍스트를 바꿀 수 없습니다.

  28. 28

    C의 텍스트 파일에서 구조를 읽을 수 없습니다.

  29. 29

    Objective-C : 합성 변수에 액세스 할 수 없습니다.

뜨겁다태그

보관