what's with all of these errors? - objective-c

#import <UIKit/UIKit.h>
#interface ProfileViewController : UIViewController {
UIImageView *profPic;
UILabel *name;
UILabel *hosted;
UILabel *points;
UILabel *attended:
UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UIImageView profPic;
#property (nonatomic, retain) IBOutlet UILabel name;
#property (nonatomic, retain) IBOutlet UILabel hosted;
#property (nonatomic, retain) IBOutlet UILabel points;
#property (nonatomic, retain) IBOutlet UILabel attended:
#property (nonatomic, retain) IBOutlet UITableView tableView;
#end

those UI* objects should be pointers:
IBOutlet UIImageView * profPic;

Although you have not posted what exactly errors you get there're 2 obvious problems in your code:
Colon in the end of the line should be semicolon:
#property (nonatomic, retain) IBOutlet UILabel attended:
^^^
Types of properties should be pointers ('*' missed in property declarations)
#property (nonatomic, retain) IBOutlet UILabel* attended;

#property (nonatomic, retain) IBOutlet UIImageView *profPic;
Add the Asterisk(*) before the name of the object.

Related

How to add a UIView to an UIAlertView?

I have to create a custom AlertView with a view that contain some label. I create the .h and .m of CustomAlert
this is the CustomAlert.h.
#import <Foundation/Foundation.h>
#interface CustomAlert: UIView
#property (nonatomic, weak) IBOutlet UILabel *ok;
#property (nonatomic, weak) IBOutlet UILabel *ok1;
#property (nonatomic, weak) IBOutlet UILabel *ok2;
#property (nonatomic, weak) IBOutlet UILabel *ok3;
#property (nonatomic, weak) IBOutlet UILabel *ok4;
#property (nonatomic, weak) IBOutlet UILabel *ok5;
#end
and this is the CustomAlert.m.
#import "CustomAlert.h"
#implementation CustomAlert
#synthesize ok = _ok;
#synthesize ok1 = _ok1;
#synthesize ok2 = _ok2;
#synthesize ok3 = _ok3;
#synthesize ok4 = _ok4;
#synthesize ok5 = _ok5;;
#end
I also create the xib with just a view and i connect the label with all the "ok".
Now, i want to add this View to an AlertView with just an Ok button. How can i do it? I want to use it with ios 7 and 6.
Thanks!!
In iOS 7 you should not munge a UIAlertView like this - and there is no need, because thanks to custom view transitions you can make your own small presented view in front of your interface, so that it looks and acts like a UIAlertView but can contain anything you like.
I've written an online tutorial on how to do this:
http://programming.oreilly.com/2014/01/transcending-uialertview-on-ios-7.html
And there's a downloadable github project that goes with it:
https://github.com/mattneub/custom-alert-view-iOS7

Add up different slider values - Objective C

My sliders are located on 10 different views. So, I want the user to be able to select a value with ratingSliderOne, and then move on to "Page 2" and select another value etc. Those values should then be added up to a total
.h
#interface CBViewController : UIViewController
//Scorelabel
#property (nonatomic, readwrite) NSInteger theTotalScore;
#property (strong, nonatomic) IBOutlet UILabel *totalScoreLabel;
// Page 1
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderOne;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelOne;
// Page 2
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderTwo;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelTwo;
// Page 3
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderThree;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelThree;
// Page 4
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderFour;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelFour;
// Page 5
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderFive;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelFive;
// Page 6
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderSix;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelSix;
// Page 7
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderSeven;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelSeven;
// Page 8
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderEight;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelEight;
// Page 9
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderNine;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelNine;
// Page 10
#property (strong, nonatomic) IBOutlet UISlider *ratingSliderTen;
#property (strong, nonatomic) IBOutlet UILabel *repeaterLabelTen;
-(void)updateTotalScores;
- (IBAction)ratingSliderDidChange:(id)slider;
#end
.m
- (IBAction)ratingSliderDidChange:(id)slider
{
int sliderValue1 = self.ratingSliderOne.value;
int sliderValue2 = self.ratingSliderTwo.value;
int total = sliderValue1 + sliderValue2;
self.theTotalScore = total;
NSLog(#"%i, %i, %i", sliderValue1, sliderValue2, total);
[self updateTotalScores];
}
-(void)updateTotalScores{
if (_theTotalScore > 0) {
self.totalScoreLabel.text = [NSString stringWithFormat:#"%i", _theTotalScore];
NSLog(#"%i", _theTotalScore);
}
}
Currently, the NSLog(#"%i, %i, %i", sliderValue1, sliderValue2, total); returns the correc values for each slider. But when you change from page 1 (i.e. ratingSliderOne) to page 2, it "forgets" the value of ratingSliderOne.
EDIT: Added all the code and clarified the question
- (IBAction)ratingSliderDidChange:(id)slider is a delegate callback. It will be fired every time it moves or any other slider connected on the screen moves.
it sounds like what you need is inside this callback to get the value of each slider on the page and create the total each time. Like so:
- (IBAction)ratingSliderDidChange:(id)slider
{
int total = 0;
total += self.ratingSliderOne.value;
total += self.ratingSliderTwo.value;
// etc ....
self.theTotalScore = total;
NSLog(#"%i", _theTotalScore);
[self updateTotalScores];
}

How can I improve my attempt to create protected properties

#import "BGReviewController.h"
#interface BGReviewController (protected)
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
#property (weak, nonatomic) IBOutlet UIButton *dislikeButton;
#property (weak, nonatomic) IBOutlet UIButton *likeButton;
#property (weak, nonatomic) IBOutlet UIButton *post;
#property (weak, nonatomic) IBOutlet UIButton *cancel;
#property (weak, nonatomic) IBOutlet UITextView *textView;
#end
Then I add:
#synthesize backgroundImage = _backgroundImage;
#synthesize dislikeButton = _dislikeButton;
#synthesize likeButton = _likeButton;
#synthesize post = _post;
#synthesize cancel = _cancel;
#synthesize textView = _textView;
And I got error:
/business/Dropbox/badgers/BadgerNew/BGReviewController.m:32:13: Property declared in category 'protected' cannot be implemented in class implementation
Should I declare the synthesize in the implementation file of the category and then put the ivars explicitly?
you cant #synthesize in a category, you have to do the getters and setter manually
check out this answer
Replace
#interface BGReviewController (protected)
With
#interface BGReviewController ()

UITextField bind

I can't figure out why that code is not working for me.
ViewController.h
...
#property (nonatomic, copy) UITextField *textField;
...
ViewController.m
-(void)viewDidLoad
{
[self.textField addTarget:self
action:#selector(textIsChanged:)
forControlEvents:UIControlEventEditingChanged];
}
-(void)textIsChanged:(id)sender;
{
NSLog(#"Changed");
}
When I type something in the textField textIsChanged method is never invoked.
You should declare textField as an IBOutlet like this:
#property (nonatomic, retain) IBOutlet UITextField *textField;
or, if you are using ARC (Automatic Reference Counting):
#property (nonatomic, strong) IBOutlet UITextField *textField;
and bind it from the xib file in interface builder.

IOS 5 error when attempting to set label to hidden [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have a label that serves as a warning when certain conditions are not met. But when I attempt to set the label to hidden with the following code:
infoWarning.hidden = YES;
for context, here is the full code:
if (weightC < 50 || (waistM1 < 20 && waistM2 < 20 && waistM3 < 20) || (ageC < 18 ))
{
infoWarning.hidden = NO;
NSString *warning = #"";
if(ageC < 18)
{
warning = #" an age over 17";
}
if (averageWaistM < 20) {
if (warning != #"") {
warning = [NSString stringWithFormat:#"%#, and", warning];
}
warning = [NSString stringWithFormat:#"%# a waist measurement", warning];
}
if (weightC < 50) {
if (warning != #"") {
warning = [NSString stringWithFormat:#"%#, and", warning];
}
warning = [NSString stringWithFormat:#"%# a weight", warning];
}
if (warning!=#"") {
[infoWarning setText:[NSString stringWithFormat:#"Please add%#.", warning]] ;
}
} else {
if(gender.selectedSegmentIndex == 0)
{
}
else if(gender.selectedSegmentIndex == 1)
{
}
}
That I thought would work, but (obviously) does not. It gives me an EXC_BAD_ACCESS error on the line:
infoWarning.hidden = YES;
infoWarning does exist, is synthesized, and is connected to the UILabel in Interface Builder. Could you help me identify the problem and make it work?
This is the .h file:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#class Preferences;
#class Utilities;
#interface BodyFatCalculatorViewController : UIViewController {
IBOutlet UITextField *age;
IBOutlet UITextField *waist1;
IBOutlet UITextField *waist2;
IBOutlet UITextField *waist3;
IBOutlet UITextField *weight;
IBOutlet UILabel *waist;
IBOutlet UILabel *currentWeight;
IBOutlet UILabel *bodyFat;
IBOutlet UILabel *averageWaist;
IBOutlet UILabel *veryLean;
IBOutlet UILabel *veryLeanBorder;
IBOutlet UIImageView *veryLeanCheckmark;
IBOutlet UILabel *fit;
IBOutlet UILabel *fitBorder;
IBOutlet UIImageView *fitheckmark;
IBOutlet UILabel *average;
IBOutlet UILabel *averageBorder;
IBOutlet UIImageView *averageCheckmark;
IBOutlet UILabel *atRisk;
IBOutlet UILabel *atRiskBorder;
IBOutlet UILabel *atModRisk;
IBOutlet UILabel *atModRiskBorder;
IBOutlet UILabel *atHighRisk;
IBOutlet UILabel *atHighRiskBorder;
IBOutlet UILabel *infoWarning;
IBOutlet UISegmentedControl *gender;
NSMutableArray *arrayAge;
}
#property (nonatomic, retain) IBOutlet UITextField *age;
#property (nonatomic, retain) IBOutlet UITextField *waist1;
#property (nonatomic, retain) IBOutlet UITextField *waist2;
#property (nonatomic, retain) IBOutlet UITextField *waist3;
#property (nonatomic, retain) IBOutlet UITextField *weight;
#property (nonatomic, retain) IBOutlet UILabel *waist;
#property (nonatomic, retain) IBOutlet UILabel *currentWeight;
#property (nonatomic, retain) IBOutlet UILabel *bodyFat;
#property (nonatomic, retain) IBOutlet UILabel *averageWaist;
#property (nonatomic, retain) IBOutlet UILabel *veryLean;
#property (nonatomic, retain) IBOutlet UILabel *veryLeanBorder;
#property (nonatomic, retain) IBOutlet UIImageView *veryLeanCheckmark;
#property (nonatomic, retain) IBOutlet UILabel *fit;
#property (nonatomic, retain) IBOutlet UILabel *fitBorder;
#property (nonatomic, retain) IBOutlet UIImageView *fitCheckmark;
#property (nonatomic, retain) IBOutlet UILabel *average;
#property (nonatomic, retain) IBOutlet UILabel *averageBorder;
#property (nonatomic, retain) IBOutlet UIImageView *averageCheckmark;
#property (nonatomic, retain) IBOutlet UILabel *atRisk;
#property (nonatomic, retain) IBOutlet UILabel *atRiskBorder;
#property (nonatomic, retain) IBOutlet UILabel *atModRisk;
#property (nonatomic, retain) IBOutlet UILabel *atModRiskBorder;
#property (nonatomic, retain) IBOutlet UILabel *atHighRisk;
#property (nonatomic, retain) IBOutlet UILabel *atHighRiskBorder;
#property (nonatomic, retain) IBOutlet UILabel *infoWarning;
#property (nonatomic, retain) IBOutlet UISegmentedControl *gender;
-(IBAction)valueChanged:(id)sender;
-(IBAction)textFieldDoneEditing:(id)sender;
-(void)calculate;
#end
Problem has been fixed, thank you to those who responded and looked into it. The problem was actually an array with the limits that were too small (I don't know why that caused this to break, they weren't at all related...) and so I increased the limits and now the infoWarning works great.
The complete error from the console might help but given "EXC_BAD_ACCESS error" in the line
infoWarning.hidden = NO;
suggests that there is a problem with infoWarning.hidden, what are the #property and #synthesize statements?
To compare the contents of strings use:
[warning is equalToString:#""]
not:
warning != #""
which compares the pointers to the strings.
But in your case why not just use:
warning.length != 0