How can I improve my attempt to create protected properties - objective-c

#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 ()

Related

Changing label's data using textField inout

I want to change the label's text (which is embedded in a tableViewCell) using a textField data (which is embedded outside the tableViewCell).
Can anyone share the code please using objective-C.
Here is my TableViewCell.h file.
#import <UIKit/UIKit.h>
#interface TableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
Here is my storyboard controller file
#import <UIKit/UIKit.h>
#interface ViewController:UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *contacts;
}
- (IBAction)leftBtn:(id)sender;
- (IBAction)rightBtn:(id)sender;
- (IBAction)nextBtn:(id)sender;
- (IBAction)SendBtn:(id)sender;
#property (strong, nonatomic) IBOutlet UITableView *tabV1;
#property (strong, nonatomic) IBOutlet UITextField *txtField;
#end
Here I have the button action connection where I should I write the actual code to change the label's data using a text field.
- (IBAction)leftBtn:(id)sender {
}

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];
}

Expected specifier-qualifier-list - Why?

I've got an app I'm working on, its got 4 views so far that work fine, I've added another view (with .h & .m files) and now it wont compile. I've copied the code from the other lines but cannot figure out the problem.
the error is on line IBOutlet fifthViewController *fifthViewController;
#import <UIKit/UIKit.h>
#class FirstViewController;
#class SecondViewController;
#class ThirdViewController;
#class ForthViewController;
#class fifthviewcontroller;
#interface MulipleViewsViewController : UIViewController {
IBOutlet FirstViewController *firstViewController;
IBOutlet SecondViewController *secondViewController;
IBOutlet ThirdViewController *thirdViewController;
IBOutlet ForthViewController *forthViewController;
IBOutlet fifthViewController *fifthViewController;
}
#property (retain, nonatomic) FirstViewController *firstViewController;
#property (retain, nonatomic) SecondViewController *secondViewController;
#property (retain, nonatomic) ThirdViewController *thirdViewController;
#property (retain, nonatomic) ForthViewController *forthViewController;
#property (retain, nonatomic) fifthviewcontroller *FifthViewController;
-(IBAction) loadSecondView:(id)sender;
-(IBAction) loadThirdView:(id)sender;
-(IBAction) loadFirstView:(id)sender;
-(IBAction) loadForthView:(id)sender;
-(IBAction) loadFifthView:(id)sender;
-(void) clearView;
#end
I think the problem is here:
#property (retain, nonatomic) fifthviewcontroller *FifthViewController;
it should be:
#property (retain, nonatomic) Fifthviewcontroller *fifthViewController;
and of course
IBOutlet fifthViewController *fifthViewController;
should be:
IBOutlet FifthViewController *fifthViewController;
here too:
#class fifthviewcontroller;
should be
#class FifthViewcontroller;
When you declare the class and property, you use fifthviewcontroller with no capitals, but when you declare the instance variable, you capitalize the V and C: fifthViewController. From the context, it appears that the capitalizations are a mistake and that line should be changed to IBOutlet fifthviewcontroller *fifthViewController;
In the future, when posting about errors, please indicate in the code which line the error occurs on.

what's with all of these errors?

#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.