so I'm writing Obj-C for iOS, and something "strange" is happening..
I have an MVC, with a UITableView (private):
#interface MVC ()
#property (strong, nonatomic) IBOutlet UITableView *tableView;
#property (strong, nonatomic) CellVC *cell1;
#property (strong, nonatomic) CellVC *cell2;
#end
I load the table view up with a few custom cells. My custom cell class is actually a UIViewController... so I instantiate a few, and set cell.contentView to the corresponding CellVC.view inside the tableView:cellForRowAtIndexPath: method. My custom cell class:
#interface CellVC : UIViewController
#property (strong, nonatomic) IBOutlet UIKnob *knob1;
#property (strong, nonatomic) IBOutlet UIKnob *knob2;
#property (strong, nonatomic) IBOutlet UIKnob *knob3;
#property (strong, nonatomic) IBOutlet UIKnob *knob4;
#end
In case you're wondering, I've written a subclass of UIControl named UIKnob...
In CellVC's viewDidAppear: method, I've set a breakpoint to check the values of every knob. Each knob is non-nil, so I am happy... they have all been created.
My goal is to set MVC as the delegate of each knob. (4 knobs for each cell)
If I set a breakpoint anywhere in MVC, the value of each knob is nil??...
cell1.knob1.delegate = self;
will not work because the knobs only exist inside CellVC.m ...
Any ideas??
Related
Iam a newbie in iOS Development.
outlets are displayed in intellisense on .m file if i type first characters but i want to see only list of outlets in intellisense like listing only methodnames of object .
Is there a way to list only outlets in intellisense when i want?
Do i always have to switch to .h file to see the list of outlets?
.h file outlets
#property (weak, nonatomic) IBOutlet UIImageView *searchImage;
#property (weak, nonatomic) IBOutlet UIButton *searchbutton;
#property (weak, nonatomic) IBOutlet UILabel *mainLabel;
#property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
Use this line in .m file after implementation
#synthesize searchImage,searchbutton,mainLabel,activityIndicator;
To access them just write their name and use it
[activityIndicator stopAnimating];
mainLabel.text = #"ss";
I currently have a header that displays a name, time, and a couple of buttons. This header should only appear if an appointment is selected in a dashboard, which is irrelevant here. However, once i logout and log back in, with no patient selected, the header view is displayed. I think this is because I did not deallocate the appointment object, and i'm not sure how to do that (i'm new to iOS programming).
Here's my code:
So I have the interface
#interface DashboardVC : CommonVC <UIActionSheetDelegate, HeaderViewDelegate, PracticeServiceDelegate> {
IBOutlet HeaderView *_headerView;
}
And inside the HeaderView object i have these properties:
#property (strong, nonatomic) CCAppointment *appointment;
#property (strong, nonatomic) IBOutlet UIButton *backButton;
#property (strong, nonatomic) IBOutlet UIView *currentPatientView;
#property (strong, nonatomic) IBOutlet UIImageView *avatarImageView;
#property (strong, nonatomic) IBOutlet UILabel *patientNameLabel;
I then, in dashboard VC, want to deallocate, but i'm not sure how... this is what i have:
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
How do I deallocate the properties so that the headerVIew does not show up?
if you want to destroy _headerView try:
[_headerView removeFromSuperview];
_headerView = nil;
I declare my .h file like this:
#import <UIKit/UIKit.h>
#interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
NSArray *questionTitleTrip;
NSArray *questionDescTrip;
NSMutableArray *answerTrip;
NSMutableArray *pickerChoices;
int questionInt;
int totalInt;
IBOutlet UILabel *questionNum;
IBOutlet UILabel *questionTotalNum;
IBOutlet UILabel *recordType;
IBOutlet UITextView *questionDes;
IBOutlet UIView *answerView;
IBOutlet UIButton *preButton;
IBOutlet UIButton *nextButton;
UITextField *text;
UIPickerView *picker;
}
#property (retain, nonatomic) NSArray *questionTitleTrip;
#property (retain, nonatomic) NSArray *questionDescTrip;
#property (retain, nonatomic) NSMutableArray *answerTrip;
#property (retain, nonatomic) NSMutableArray *pickerChoices;
#property (retain, nonatomic) IBOutlet UILabel *questionNum;
#property (retain, nonatomic) IBOutlet UILabel *questionTotalNum;
#property (retain, nonatomic) IBOutlet UILabel *recordType;
#property (retain, nonatomic) IBOutlet UITextView *questionDes;
#property (retain, nonatomic) IBOutlet UIView *answerView;
#property (retain, nonatomic) IBOutlet UIButton *preButton;
#property (retain, nonatomic) IBOutlet UIButton *nextButton;
#property (retain, nonatomic) UITextField *text;
#property (retain, nonatomic) UIPickerView *picker;
-(IBAction)clickPre;
-(IBAction)clickNext;
#end
And my .m file here like this:
#import "NavigationTripViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface NavigationTripViewController ()
#end
#implementation NavigationTripViewController
#synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker;
All my variables in the #synthesize receive the warnings:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'
Also, the variables and class names used in viewDidLoad don't display in colors, just show in black color. In other view controllers, there are no warnings like this. How to fix these problems?
Edit:
Basically for all intents and purposes you should be building on a new enough XCode to use the new behavior, in that solution you typically will just remove the ivar from the #interface block in the .h file... If for some reason you do need to access an ivar directly you can now declare it in the #implementation block... and use #synthesize var or #synthesize var=_var
OGPost:
to make that go away you can go all new school and drop the iVar, or you can go all old school and add an #synthesize someIvar in your #implementation block.
In my collectionView based app i want to cache the last 100 cells loaded, and i think best way for me is to work with core data.
I already have a custom class for UICollectionViewCell, and obviously all the cells are objects of this class. it's look kind of like this:
#interface Cell : UICollectionViewCell
#property (strong, nonatomic) NSString *cellFacebookId;
#property (strong, nonatomic) NSString *cellMail;
#property (strong, nonatomic) NSString *cellAddId;
#property (strong, nonatomic) NSString *cellCategory;
#property (strong, nonatomic) IBOutlet UIImageView *cellBackImg;
#property (strong, nonatomic) IBOutlet UIImageView *titleBarImage;
#end
Now I've created an entity named Cell, with same attributes. can i create a NSManagedObject subclass that will replace my original "Cell" class and still use it as UICollectionViewCell custom class?
You can't use a subclass of NSManagedObject as a UICollectionView cell. It has to be a subclass of UICollectionViewCell. Besides UICollectionView reuses cells by caching them.
I have a custom view - DetailSubView.h with labels
#property (retain, nonatomic) UILabel *titleLabel;
#property (retain, nonatomic) UILabel *descHeaderLabel;
On custom UICollectionViewCell, i have
#property (strong, nonatomic) DetailSubView *detailView;
When I set text, i received unrecognized selector error.
[self.detailView.titleLabel setText:#"text"];
That's because your titleLabel is declared in DetailView but you're trying to access it from a class of type DetailSubView. It cannot access the getter method for your property on DetailSubView since you don't have it declared there.