UIButton won't hide/unhide - ios

I set UIButton myButton to hidden on viewDidLoad
In a splitviewcontroller I have it so that when I click on a tablecell, certain items unhide which works great for my textviews but my button is giving me this:
ERROR: member reference base type void is not a structure or union
Here is some snippet of code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
detailViewController.myButton.hidden= NO;
detailViewController.textView1.hidden= NO;
detailViewController.textView2.hidden= NO;
}
in the .h file there is
#property (strong, nonatomic) DetailViewController *detailViewController;
in DetailViewController is where the button and textviews are declared as
#interface DetailViewController : UIViewController <UISplitViewControllerDelegate>{
IBOutlet UIButton *myButton;
IBOutlet UITextView *textView1;
IBOutlet UITextView *textView2;
}
#property (strong, nonatomic) IBOutlet UITextView *textView1;
#property (strong, nonatomic) IBOutlet UITextView *textView2;
#property (strong, nonatomic) UIButton *myButton;
-(IBAction)myButtonPressed;
#end
IBAction myButtonPressed in the DetailViewController.m is
-(IBAction)myButtonPressed{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
RootViewController *RVC = [storyboard instantiateViewControllerWithIdentifier:#"Root"];
[UIApplication sharedApplication].delegate.window.RootViewController = RVC;
}
Anyone have any thoughts on why the button won't behave like the other two will? Is it because I gave it an IBAction??

You forget to Put IBOutlet at the first of button creation it should be
#property (strong, nonatomic) IBOutlet UIButton *myButton; OR
#property (nonatomic, weak) IBOutlet UIButton *myButton;
And give proper connection to file's owner.

Button should be a IBOutlet and please correct it and update XIB references and you should be good.
#property (nonatomic, weak) IBOutlet UIButton * myButton;
link this to UIButton is XIB if you are using one.

Related

-[MyDictationController respondsToSelector:] message sent ot deallocated instance

My app crashes with this stack trace:
[DictationDetailsController respondsToSelector:]: message sent to deallocated instance
I tracked that on instruments trying to see the relevant code causing the crash:
here is the relevant code for MyDictationController in the didSelectRowAtIndexPath: delegate method:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath {
DictationDetailsController *controller = GET_CONTROLLER_WITH_CLASS([DictationDetailsController class]);
controller.dictation = [unSubmittedDictations objectAtIndex:indexPath.row];
controller.isEditMode = YES;
controller.selectedDate = _selectedDate;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#property (copy ,nonatomic) Dictation *dictation;
Also i have used #synthesize. Help me out in this issue, to get which deallocated method is being called.?
Here's my DictationDetailsController interface:
#interface DictationDetailsController : BaseController
#property (copy ,nonatomic) Dictation *dictation;
#property (nonatomic) BOOL isEditMode;
#property (nonatomic) NSDate *selectedDate;
#property (weak, nonatomic) IBOutlet UILabel *navigationTitleLabel;
#property (weak, nonatomic) IBOutlet UITextField *patientNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *accountIDTextField;
#property (weak, nonatomic) IBOutlet UITextField *workTypeTextField;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidth;
#property (weak, nonatomic) IBOutlet UIView *tutorialView;
#property (weak, nonatomic) IBOutlet UIView *audioContainer;
#property (weak, nonatomic) IBOutlet UISlider *audioSlider;
#property (weak, nonatomic) IBOutlet UILabel *durationLabel;
#property (weak, nonatomic) IBOutlet UILabel *noRecordingLabel;
#property (weak, nonatomic) IBOutlet UIButton *playPauseButton;
#end
And in dealloc method:
- (void)dealloc {
[player pause];
player = nil;
self.dictation = nil;
}
My guess is the issue is somewhere inside GET_CONTROLLER_WITH_CLASS method. Pop a breakpoint on that line and step over it. It's possibly producing a released instance of the class. That being the case, the crash would occur on the line immediately following the call to that method when it tries to access the dictation property.

About Property not found Xcode 5 error

Here InformacionViewController.h:
#import <UIKit/UIKit.h>
#import "LibrosFenomenales.h"
#interface InformacionViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *nombre;
#property (strong, nonatomic) IBOutlet UILabel *autor;
#property (strong, nonatomic) IBOutlet UILabel *año;
#property (strong, nonatomic) IBOutlet UILabel *genero;
#property (strong, nonatomic) IBOutlet UITextView *argumento;
#property (strong, nonatomic) IBOutlet UIImageView *portada;
#property LibrosFenomenales *libroSeleccionado;
#end
Here ViewController.m:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
InformacionViewController *informacionViewController = [self.storyboard
instantiateViewControllerWithIdentifier:#"InformacionViewController"];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:informacionViewController];
informacionViewController.libroSeleccionado = [_libros objectAtIndex:indexPath.row];
[self presentViewController:navigationController animated:YES completion:nil];
}
Xcode shows me this error: Property "libroSeleccionado" not found on object of type "InformacionViewController".
This is the line: informacionViewController.libroSeleccionado = [_libros objectAtIndex:indexPath.row];
What am i doing wrong?
Thanks
Instead of Quiting the Xcode you just First clean the build. To clean the build Press command+Shift+K. then run the application even then If it doesn't work for then try this #property (strong, nonatomic) LibrosFenomenales *libroSeleccionado;
instead of #property LibrosFenomenales *libroSeleccionado;
Hard to say without having access to the whole code, but try these:
If "LibrosFenomenales" is an Objective-C class, change the property declaration to:
#property (strong, nonatomic) LibrosFenomenales *libroSeleccionado;
If the LibrosFenomenales.h header imports the InformacionViewController.h header, you have a cross-referencing issue. To fix this, open up InformacionViewController.h and replace:
#import "LibrosFenomenales.h"
by:
#class LibrosFenomenales;;
then open up InformacionViewController.m and add the #import "LibrosFenomenales.h" to it.
Don't forget to #import "InformacionViewController.m" in ViewController.m

Destination ViewController not changing after segue

My destination ViewController has a number of labels and images which need to be changed dependent on the specific previous ViewController. I have a segue set up which should change these but for some reason it is not, even though the segue is being called.
My initial ViewController has a button which has a segue passing to the next ViewController with the name "aName". I'm probably missing something simple but I have been following another section of my code which does the exact same thing and works! I have also tested that the segue is successfully being called with a NSLog which returns fine. All the IBOutlets are also assigned correctly.
Initial View Controller.m:
#import "dViewController.h"
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"aName"]) {
dViewController *dVC = (dViewController *)segue.destinationViewController;
dVC.TitleLabel.text = #"abc";
dVC.1Img.image = [UIImage imageNamed:#"somepath.jpg"];
dVC.2Img.image = [UIImage imageNamed:#"somepath2.jpg"];
[dVC.1Button setTitle:#"abcd" forState:UIControlStateNormal];
[dVC.1Button setTitle:#"efgh" forState:UIControlStateNormal];
}
Destination ViewController:
dViewController.h
#property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
#property (strong, nonatomic) IBOutlet UIImageView *1Img;
#property (strong, nonatomic) IBOutlet UIImageView *2Img;
#property (strong, nonatomic) IBOutlet UIButton *1Button;
#property (strong, nonatomic) IBOutlet UIButton *2Button;
Edit: From doing some more looking around I think I should be using a delegate. It seems quite complicated and not really sure where I start. But I'll have a go at looking at what's in this thread: Changing label's text in another view controller
you have to create a variable for each label you want to change and in viewDidLoad assing the variable to the label.text
for example
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"aName"]) {
dViewController *dVC = (dViewController *)segue.destinationViewController;
dVC.titleString = #"abc";
dVC.1Image = [UIImage imageNamed:#"somepath.jpg"];
dVC.2Image = [UIImage imageNamed:#"somepath2.jpg"];
dVC.1ButtonString=#"ButtonTitle";
dVC.2ButtonString=#"ButtonTitle2";
}
in DestinationController
#property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
#property (strong, nonatomic) IBOutlet UIImageView *1Img;
#property (strong, nonatomic) IBOutlet UIImageView *2Img;
#property (strong, nonatomic) IBOutlet UIButton *1Button;
#property (strong, nonatomic) IBOutlet UIButton *2Button;
#property(strong,nonatomic)NSString *2ButtonString;
#property(strong,nonatomic)UIImage*1Image;
#property(strong,nonatomic)UIImage*2Image;
#property(strong,nonatomic)NSString* titleString;
#property(strong,nonatomic)NSString *1ButtonString;
#property(strong,nonatomic)UIImageView *1Img;
#property(strong,nonatomic)UIImageView *1Img;
- (void)viewDidLoad{
self.TitleLabel.text = self.titleString;
self.1Img.image = self.1Image;
self.2Img.image = self.2Image;
[self.1Button setTitle:self.1ButtonString];
[self.2Button setTitle:self.1ButtonString];
}
hope It help you, the problem is that with
dViewController *dVC = (dViewController *)segue.destinationViewController;
you only bring the controller not the view. and the IBOutlet belongs to the view and the view is not load i hope you understand
Read about app navigation principles. From apple:
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html
Put parentheses around segue.destinationViewController like this:
dViewController *dVC = (dViewController *)(segue.destinationViewController);

UILabel text property iOS

I would like to modify the text property of a UILabel (nameLbl) but don't know what i am wrong.
I have 2 Views, the first is a ViewController, the second is ProfileViewController. The ProfileViewController fill some field of user profile this data are passed to ViewController and showed in UIlabel.
The issue is I can't show the datas in the ViewController.
What am I get wrong?
---ViewController.h---
#interface ViewController : UIViewController
{
IBOutlet ViewController *profile;
IBOutlet UILabel *nameLbl, *celLbl, *cfLbl;
IBOutlet UITextField *nameTF;
}
#property (nonatomic, retain) IBOutlet ViewController *profile;
#property (retain, nonatomic) IBOutlet UILabel *nameLbl, *celLbl, *cfLbl;
#property (nonatomic, retain) IBOutlet UITextField *nameTF;
-(void) setUser: (NSString *) name:(NSString *) cel:(NSString *) cf;
#end
---ViewController.m---
#synthesize nameLbl, celLbl, cfLbl;
-(void) setUser:(NSString *)name:(NSString *)cel:(NSString *)cf
{
nameLbl = [[UILabel alloc] init];
[nameLbl setText:name];
}
this is the connection inspector
https://drive.google.com/file/d/0Bz7WcQmZNuFLMWt3QUo1Tk5XUW8/edit?usp=sharing
Remove
nameLbl = [[UILabel alloc] init];
from your code it seems that the nameLbl UILabel has already been initialized from nib, and you are creating a new memory reference, so its not working.

IB Connections in Xcode crashing

I was working on my iOS app last night when I went to test it and it crashed on startup. I wasn't even working on the nib that is causing the crash. Anyways, here is the error code:
2/29/12 10:32:05.291 AM Safe Flight: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xdd496f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Airport1.'
*** First throw call stack:
(0x2873052 0x33add0a 0x2872f11 0x1ae2032 0x1a53f7b 0x1a53eeb 0x1a6ed60 0x136191a 0x2874e1a 0x27de821 0x136046e 0x1362010 0x114214a 0x1142461 0x11417c0 0x1150743 0x11511f8 0x1144aa9 0x37b7fa9 0x28471c5 0x27ac022 0x27aa90a 0x27a9db4 0x27a9ccb 0x11412a7 0x1142a9b 0x3710 0x2f35)
Airport1 is just a label with an IBOutlet correctly connected to it. Also, if I delete the connection the error just is with the next item that has an connection.
Also, my FileOwners class it correctly set to the appropriate viewController.
// MasterViewController.h
#import <UIKit/UIKit.h>
#import "MobclixAds.h"
#class DataViewController;
#class EditViewController;
#class SearchViewController;
#interface MasterViewController : UIViewController{
UILabel *Airport1;
UILabel *Airport2;
UILabel *Airport3;
UILabel *Airport4;
UILabel *Airport5;
UILabel *Airport6;
UILabel *Airport7;
UILabel *Airport8;
UILabel *Airport9;
UIButton *Airport1B;
UIButton *Airport2B;
UIButton *Airport3B;
UIButton *Airport4B;
UIButton *Airport5B;
UIButton *Airport6B;
UIButton *Airport7B;
UIButton *Airport8B;
UIButton *Airport9B;
MobclixAdView* adView;
}
#property (strong, nonatomic) DataViewController *dataViewController;
#property (strong, nonatomic) EditViewController *editViewController;
#property (strong, nonatomic) SearchViewController *searchViewController;
#property (nonatomic, retain) IBOutlet UILabel *Airport1;
#property (nonatomic, retain) IBOutlet UILabel *Airport2;
#property (nonatomic, retain) IBOutlet UILabel *Airport3;
#property (nonatomic, retain) IBOutlet UILabel *Airport4;
#property (nonatomic, retain) IBOutlet UILabel *Airport5;
#property (nonatomic, retain) IBOutlet UILabel *Airport6;
#property (nonatomic, retain) IBOutlet UILabel *Airport7;
#property (nonatomic, retain) IBOutlet UILabel *Airport8;
#property (nonatomic, retain) IBOutlet UILabel *Airport9;
#property (nonatomic, retain) IBOutlet UIButton *Airport1B;
#property (nonatomic, retain) IBOutlet UIButton *Airport2B;
#property (nonatomic, retain) IBOutlet UIButton *Airport3B;
#property (nonatomic, retain) IBOutlet UIButton *Airport4B;
#property (nonatomic, retain) IBOutlet UIButton *Airport5B;
#property (nonatomic, retain) IBOutlet UIButton *Airport6B;
#property (nonatomic, retain) IBOutlet UIButton *Airport7B;
#property (nonatomic, retain) IBOutlet UIButton *Airport8B;
#property (nonatomic, retain) IBOutlet UIButton *Airport9B;
#property(nonatomic,retain) IBOutlet MobclixAdView* adView;
#end
and
// MasterViewController.m
#import "MasterViewController.h"
#import "DataViewController.h"
#import "EditViewController.h"
#import "SearchViewController.h"
#implementation MasterViewController
#synthesize dataViewController = _dataViewController;
#synthesize editViewController = _editViewController;
#synthesize searchViewController = _searchViewController;
#synthesize Airport1, Airport2, Airport3, Airport4, Airport5, Airport6, Airport7, Airport8, Airport9;
#synthesize Airport1B, Airport2B, Airport3B, Airport4B, Airport5B, Airport6B, Airport7B, Airport8B, Airport9B;
#synthesize adView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Safe Flight";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
}
return self;
}
So is my problem with my code? or with Xcode itself?? I have restarted Xcode and the simulator and even did a "clean" build (it sounded like it would help...)
Thanks,
Andrew
EDIT This is my AppDelegate and I'm setting the correct xib to the window
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Mobclix start];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
PROBLEM SOLVED!!!
I can't answer my own question because of some stupid spam filter... and I can post a picture of the problem... but its fixed!
but here is a link to the problem click here
Found the Problem!! I feel kinda stupid now ;) but anyways, here is a screenshot of the problem!
The reason causing to crash could be the connection mistakes within xib to header.
Airport1 could be connected to another class than MasterViewController.
If your label connected to File's Owner - it should be MasterViewController.
If you've created another UIViewController within xib and connected Airport1 label to it, then this controller also should be connected to MasterViewController (Identity Inspector "Class" field.)
Updated. Added Screenshots:
When you initialize the MasterViewController (wherever you are launching it from), make sure you are initializing it with the appropriate nib file
Ex.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"YourNibName" bundle:nil];

Resources