Semantic issue: Property 'text' not found on object of type 'UISlider' - xcode

When I try to run it though, I get an error which says "Semantic issue: Property 'text' not found on object of type 'UISlider'"
What's wrong here?
Here is the code from the header file:
#import <UIKit/UIKit.h>
#interface BIDViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *nameField;
#property (strong, nonatomic) IBOutlet UITextField *numberField;
#property (strong, nonatomic) IBOutlet UISlider *sliderLabel;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
- (IBAction)sliderChanged:(id)sender;
#end
Implementation file:
#import "BIDViewController.h"
#implementation BIDViewController
#synthesize sliderLabel;
#synthesize nameField;
#synthesize numberField;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setNameField:nil];
[self setNumberField:nil];
[self setSliderLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender
{
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)roundf(slider.value);
sliderLabel.text = [NSString stringWithFormat:#"%d",progressAsInt];
}
#end

I suspect your sliderLabel has been declared as an object of class UISlider, when it should be UILabel. Can you verify the sliderLabel's #property declaration in your header file?

I have the same message on NSManagedObject. My solution is set "Always Search User Paths" in "Search Paths" of target's Build Settings to "No"
Hope that could help too.

Related

Setting dataSource for NSTableView across scenes in a storyboard

I am using XCode 6 on OS X 10.10 and have a storyboard containing a window with a split view controller, as shown in the following image.
The split view controller (highlighted in the image) is an instance of MyViewController, which has the following code:
MyViewController.h
#import <Cocoa/Cocoa.h>
#interface MyViewController : NSSplitViewController <NSTableViewDataSource>
#end
MyViewController.m
#import "MyViewController.h"
#implementation MyViewController
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return 7;
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
return [NSString stringWithFormat:#"%ld", (long)row];
}
#end
I would like to make the view controller the dataSource of the NSTableView in my storyboard, however I am unable to connect them. Is there a reason for this?
In your NSSplitViewController-subclass viewDidLoad-method set the data source programmatically. You need to implement the child view controller class as well (with the tableView outlet connected to the control).
MySplitViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
for (NSSplitViewItem *item in self.splitViewItems)
{
NSViewController *controller = item.viewController;
if ([controller isKindOfClass:[MyChildController class]])
{
MyChildController *myController = (MyChildController *)controller;
myController.tableView.dataSource = self;
[myController.tableView reloadData];
}
}
}
But to tell you the truth I don't like this approach. It's more better when the table view's data source methods are in the native view controller class.
Another way to do that. MyChildController.h file:
#class MyChildViewController;
#protocol MyChildControllerDelegate <NSObject>
- (void)childController:(MyChildViewController *)controller didSelectRowAtIndex:(NSUInteger)index;
#end
#interface MyChildViewController : NSViewController <NSTableViewDataSource, NSTableViewDelegate>
#property (nonatomic, weak) id<MyChildControllerDelegate> delegate;
#property (nonatomic, retain) NSArray *items;
#property (nonatomic, weak) IBOutlet NSTableView *tableView;
#end
Don't forget to implement all the table view dataSource and delegate methods you need. MySplitViewController.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
for (NSSplitViewItem *item in self.splitViewItems)
{
NSViewController *controller = item.viewController;
if ([controller isKindOfClass:[MyChildController class]])
{
MyChildController *myController = (MyChildController *)controller;
myController.delegate = self;
[myController setItems:_items];
}
}
}

iOS 7: Cannot connect to IBOutlets, probably because I'm using UITableViewController

I cannot create any IBOutlets. I'm using a tableviewcontroller instead of a viewcontroller.
When I click on TableViewController, the class is UITableViewController and I can't change that.
Here's my code for ViewController.h:
// ViewController.h
// Tips4
//
// Created by Meghan on 1/20/14.
// Copyright (c) 2014 Meghan. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (strong, nonatomic) IBOutlet UILabel *sliderDisplay;
#property (strong, nonatomic) IBOutlet UITextField *tempText;
#property (strong, nonatomic) IBOutlet UILabel *billTotal;
#property (nonatomic, strong) IBOutlet UISlider *slider;
- (IBAction)sliderValueChanged:(id)sender;
#property (nonatomic) float answer;
#property (nonatomic) float answerTwo;
#end
Here's my ViewController.m:
// ViewController.m
// Tips4
//
// Created by Meghan on 1/20/14.
// Copyright (c) 2014 Meghan. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tipsTableIdentifier = #"TipsTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tipsTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tipsTableIdentifier];
}
return cell;
}
- (IBAction)sliderValueChanged:(id)sender
{
float theText = [_tempText.text floatValue];
_answer = (_slider.value * theText) / 100;
_answerTwo = _answer + theText;
_sliderDisplay.text = [NSString stringWithFormat:#"%1.2f", _answer];
_billTotal.text = [NSString stringWithFormat:#"%1.2f", _answerTwo];
}
- (void)viewDidLoad
{
[super viewDidLoad];
_tempText.keyboardType = UIKeyboardTypeDecimalPad;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
If you’re using a TableViewController, your class must inherit from a UITableViewController. Thats when it will show up in the Identity Inspector, which is where you change your class from UIViewController to your class. After that you should be able to connect IBOutlets.
To do that, just replace your current line
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
with
#interface ViewController : UITableViewController
Now, you will need to add the init method that calls the super, to the .m file.
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
I hope this will do it.
Also, sometimes, changes in the code don’t show up in the storyboard Identity Inspector. In that case, you can just quit the Xcode window and open the project again. That does it.
Alternatively, if you use a ViewController, your class can inherit from a UIViewController. Then you add a TableView to your View and add a UITableView instance to the controller file (create an IBOutlet). In this case, your .h file needs to add the UITableViewDelegate and UITableViewDataSource to populate the table and your .m file needs to implement the required methods (Xcode will warn you about this).

Save UIImageView When Unload A View - Xcode 4.5.1

Creating an app on Xcode 4.5.1 and wondering how do i save the current image in the specified UIImageView when i navigate to a different view. Then when i return to the View it loads up the saved image into the UIImageView?
Thank a lot, appreciate it :D
The code I've posted below involves passing a uiimage to a second view controller. It also includes a button on each controller to move back and forth between the two. The saved image will stay in the uiimageview when you switch to and from the views.
SecondView.h
#import <UIKit/UIKit.h>
#interface SecondView : UIViewController {
IBOutlet UIImageView *yourphotoview;
UIImage *yourimage;
}
#property (retain, nonatomic) UIImage *yourimage;
- (IBAction)back;
#end
SecondView.m
#import "ViewController.h"
#import "SecondView.h"
#interface SecondView ()
#end
#implementation SecondView
#synthesize yourimage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
yourphotoview.image = image;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back {
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)dealloc {
[image release];
[super dealloc];
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import "SecondView.h"
#interface ViewController : UIViewController
{
IBOutlet UISlider *compression;
IBOutlet UISwitch *smurferderp;
SecondView *SecondViewdata;
}
#property (retain, nonatomic) SecondView *SecondViewdata;
#property (retain, nonatomic) IBOutlet UIImageView *theimage;
- (IBAction)switchview:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import "SecondView.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize SecondViewdata, theimage;
- (IBAction)switchview:(id)sender {
SecondView *secondview = [self.storyboard instantiateViewControllerWithIdentifier:#"rr"];
self.SecondViewdata = secondview;
SecondViewdata.yourimage = theimage.image;
[self presentViewController: secondview animated:YES completion:NULL];
}
- (void)dealloc {
[theimage release];
[super dealloc];
}
#end

Impossibility to show in a label the text of an object

My objective is to show in a label the text of an object of a custom class called Files. Here is Files.h :
#import <Foundation/Foundation.h>
#interface Files : NSObject
#property (nonatomic, retain) NSString *title;
#property (nonatomic, retain) NSString *text;
#end
This is Files.m :
#import "Files.h"
#implementation Files
#dynamic title;
#dynamic text;
#end
Here is the .h file of my app. the label is called trackName:
#import <UIKit/UIKit.h>
#import "Files.h"
#interface FirstViewController : UIViewController
{
Files *plainpalais;
}
#property (weak, nonatomic) IBOutlet UILabel *trackName;
-(Files*) chooseFile;
#end
This is the .m file of the app:
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize trackName;
-(Files*)chooseFile
{
return plainpalais;
}
- (void)viewDidLoad
{
[super viewDidLoad];
plainpalais.text=#"hello";
plainpalais.title=#"plainpalais";
trackName.text=plainpalais.title;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTrackName:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
The problem is that the label trackName doesn't show plainpalais...
Thanks for help !
PS: I'm a beginner so this is probably a basic mistake.
You have used #dynamic in your Files.m implementation which tells the compiler that you'll provide getters/setters for these properties at a later time, i.e. using the Objective-C runtime.
I suspect you want to use #synthesize rather than #dynamic. For example,
#import "Files.h"
#implementation Files
#synthesize title;
#synthesize text;
#end
Also you haven't actually created a Files object in the code you have given us. The chooseFile method appears to be returning a nil object (assuming you haven't initialised plainpalais somewhere else). Perhaps you should initialise plainpalais in an init method, e.g.
- (id)init {
self = [super init];
if (self) {
plainpalias = [[Files alloc] init];
}
return self;
}
Don't forget to release this object in dealloc (if you aren't using ARC).

how to set the property of the ViewController before presenting it as presentModalViewController?

I present the view controller like this:
FBViewController *fbViewController =[[FBViewController alloc] initWithNibName:#"FBViewController" bundle:nil];
fbViewController.label.text=#"hello"; // I set the value of the property label which is the outlet
[self presentModalViewController:fbViewController animated:YES];
FBViewController.h:
#import <UIKit/UIKit.h>
#interface FBViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *label;
#end
FBViewController.m:
...
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"%#", self.label.text); // Here instead of "hello" i get the value which was in nib file.
}
...
The question is how to set the value of the label?
You can pass the NSString retrieve text to assign label modalview controller:
FBViewController *fbViewController =[[FBViewController alloc] initWithNibName:#"FBViewController" bundle:nil];
fbViewController.labeltext=#"Your Text";
[self presentModalViewController:fbViewController animated:YES];
FBViewController.h
#interface FBViewController : UIViewController {
NSString *labeltext;
}
#property (nonatomic, retain) NSString *labeltext;
and use view to load method in FBViewController.m
- (void)viewDidLoad {
label1.text=labeltext;
}

Resources