현재 처음으로 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] 삭제
몇 마디 만하겠습니다