No visible #interface for UIButton declares the selector"setbookmarkState - iphone

Declared BOOL
#property (nonatomic, assign) BOOL BookmarkState;
When using the BOOL for UIButton added on navigationbar using storyboard
[_bookmarkbtn setBookmarkState:NO];
then gets ARC Semantic issue
No visible #interface for UIButton declares the selector"setbookmarkState
EDIT:
PageViewController h file
#interface PageViewController : UIViewController <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
#property (nonatomic, assign) BOOL BookmarkState;
#end
PageViewController m file
#interface PageViewController () {
BOOL BookmarkState;
}
#property (strong, nonatomic) IBOutlet UIButton *bookmarkbtn;
#implementation PageViewController

UIButton has no property called bookmarkState.
If you want to disable your button bookmarkbtn, use [_bookmarkbtn setEnabled:NO];
Or if you want to deselect it, use [_bookmarkbtn setSelected:NO];
Or if you want to unhighlight it, use [_bookmarkbtn setHighlighted:NO];
If you want to set the bookmarkState to NO, use [self setBookmarkState:NO];
Edit: it seems like you've named the booleans differently (one with lowercase, and one with uppercase) so my question is - are you certain of what are you doing / of what are you trying to accomplish?
Pardon me if it will sound rude or disrespectful, but calling setbookmarkState on UIButton is clearly showing that you aren't quite sure of how to do something you that you need.
Also, XCode should give you an error stating that no visible interface for UIButton declares the selector setbookmbarState:
First of all - as stated, UIButton has no property bookmarkState.
Then, calling an autosynthesized setter method always implies that you use setMyProperty, not setmyProperty, or setmyproperty. It's weird how you got it to run :)
Good luck!

Related

iOS 6 issue during setting text on a label

I've a problem with some label. I made a public method that takes information from a table view and shows this info in 3 label, a text view and it load a pic from the web. I setup all the variable in the table view didSelectRowAtIndexPath method, but I'm having some issue to display that info. I made so:
in the table view controller I called the other method so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.detailCharacterViewController = [[DetailCharacterViewController alloc] init];
[self.detailCharacterViewController setupDetailViewControllerWithName:[self.arrayCharacters[indexPath.row] objectForKey:#"name"] andSurname:[self.arrayCharacters[indexPath.row] objectForKey:#"surname"] andKind:[self.arrayCharacters[indexPath.row] objectForKey:#"kind"] andDescription:[self.arrayCharacters[indexPath.row] objectForKey:#"description"] andImage:[self.arrayCharacters[indexPath.row] objectForKey:#"URLpic"]];
}
and I implemented the method so:
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url {
NSLog(#"name = %#", name);
self.labelName.text = name;
self.labelSurname.text = surname;
self.labelKind.text = kind;
self.textDescription.text = description;
NSURL *urlPic = [NSURL URLWithString:url];
NSData *dataPic = [NSData dataWithContentsOfURL:urlPic];
[self.imagePic setImage:[UIImage imageWithData:dataPic]];
}
If I look to the log i see the right things, but if I look to the GUI on iPhone or iPhone simulator it will remain blank. What's wrong with this code?
Thank you for the suggestion.
#Alex Blundell
#import <UIKit/UIKit.h>
#interface DetailCharacterViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *labelName;
#property (weak, nonatomic) IBOutlet UILabel *labelSurname;
#property (weak, nonatomic) IBOutlet UILabel *labelKind;
#property (weak, nonatomic) IBOutlet UIImageView *imagePic;
#property (weak, nonatomic) IBOutlet UITextView *textDescription;
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url;
#end
The problem is that your DetailCharacterViewController's view is not loaded yet when you call setupDetailViewControllerWithName:..., so none of the outlets are connected (yet). Instantiating a view controller via alloc-init does not load its view automatically.
You could force loading the view by calling [self view] at the beginning of your setup method. This works because accessing the view property will automatically load the view if it wasn't loaded before.
Alternatively, you could make the name, surname, etc. NSString properties of the view controller and set the corresponding labels in viewDidLoad.
Are you using Interface Builder/Storyboards to design your interface? Have you made sure to connect the IBOutlets for each UITextField/View?
You should identify the objects in the header file on your view controller class, and ensure they're prefixed by IBOutlet for them to appear in Interface Builders connections pane. E.g.
IBOutlet UITextField labelName;
[...]
Then you need to go to IB and go to the connections pane for the view controller to connect each text field/view.
This problem happened to me as well.
It has to do with the fact that iOS actually hooks up your outlets really really late.
If you put a breakpoint in your setupDetailViewControllerWithName: and check your IBOutlet variables, they will be nil. That's why you are seeing a blank view. (The good old nil erroring)
The work-around I will do is to declare properties in the DetailCharacterViewController class. (Such as #property (copy, nonatomic) NSString* name).
And in the place where you are calling setupDetailViewControllerWithName:, set those properties instead such as:
self.detailCharacterViewController.name = name;
Finally in your DetailCharacterViewController's viewDidLoad:, you set the values of the labels using the saved properties. (The outlets are for sure hooked up then).
(By the way, this problem exists for prepareForSegue: as well. The destination view controller's outlets are all still nil in prepareForSegue:. So you cannot set them directly there yet)

how to make a drop down list for iphone application

I want to make a drop down list for iphone application i want that when user click it show list and when click on any button it shows that value and hides list i have implemented using the follwoing code but this work only for one value not for others
#interface DropDownViewController : UIViewController {
IBOutlet UILabel*ddText;
IBOutlet UILabel*ddMenu;
IBOutlet UIButton*ddMenuShowButton;
}
#property (nonatomic, retain) IBOutlet UILabel *ddText;
#property (nonatomic, retain) IBOutlet UIView *ddMenu;
#property (nonatomic,retain) IBOutlet UIButton *ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender;
- (IBAction)ddMenuSelectionMade:(UIButton *)sender;
#end
#implementation DropDownViewController
#synthesize ddMenu, ddText;
#synthesize ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender
{
self.ddMenu.hidden = NO;
[sender setTitle:#"▲" forState:UIControlStateNormal];
}
- (IBAction)ddMenuSelectionMade:(UIButton *)sender
{
self.ddText.text = sender.titleLabel.text;
[self.ddMenuShowButton setTitle:#"▼" forState:UIControlStateNormal];
self.ddMenu.hidden = YES;
}
I have three button red grenn blue first is red it works only for red only not for others how to solve this i have used this following this tutorial
http://www.edumobile.org/iphone/iphone-programming-tutorials/a-simple-drop-down-list-for-iphone/
Add UIbutton near your textfield.While clicking that button create UITableview according to your textfileld size.(Hope you know about creating Uitableview)and then load your listview contents in "cellForRowIndex".While selecting the row of the table,you can get the value from "didselectrowatIndexPath" and load it in textfield.After that remove UItableview.
It would be good if you use iPhone tools in your application. You should use UIPickerView in the place of drop down list. It looks good and provides better interface in mobile application

How to add a popup UIView (of a customized class) on a UIViewController

I'm new on this, and I would like to get some advice because I don't know what I'm doing wrong.
I want to make an app in xcode, with a UIView with some items, and when you do something, another UIView (smaller than the first) pops up above the first UIView. The popup UIView would be a customized class.
I have started with the UIViewController template and the initial UIView, and I have linked all the items in the .storyboard, and it works. But when I create my own UIView class (from objective-C class), put the second UIView over the first in the storyboard and link it to my class, something goes wrong.
The UIView appears, but when I try to set it to hidden, it doesn't answer. It's like it's not receiving the messages, so I think I don't link it well programmatically and just appears because of the storyboard.
I don't know if I have to create another UIViewController instead of the UIView, or if this is the correct path.
Can anybody explain me a little, or just write a little code snippet with the instantiation of the second view and adding it?
Lots of thanks!!
(I paste some code, of the declaration in .h and instantiation in .m)
#import <UIKit/UIKit.h>
#import "EditView.h"
#interface ReleaseViewController : UIViewController <UIWebViewDelegate, UISearchBarDelegate> {
IBOutlet UIWebView *web;
IBOutlet UISearchBar *search;
IBOutlet EditView *evHack;
}
#property (nonatomic, retain) IBOutlet UIWebView *web;
#property (nonatomic, retain) IBOutlet UISearchBar *search;
#property (nonatomic, retain) IBOutlet EditView *evHack;
#end
- (void)viewDidLoad
{
[super viewDidLoad];
search.delegate = self;
web.delegate = self;
evHack = [evHack initWithFrame:CGRectMake(0, 44, 320, 377)];
[evHack setHidden:YES];
}
EditView Class (I still have nothing):
#import <UIKit/UIKit.h>
#interface EditView : UIView
#end
#import "EditView.h"
#implementation EditView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(#"View created");
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
initWithFrame only works when you alloc/init an app. If its already initialized, in this case by the storyboard, just set its frame:
evHack.frame = CGRectMake(0,44, 320, 377);
I don't know what it looks like in IB, But setting its frame in code may be redundant if you set it in IB too. To check whether evHack is hooked up right, NSLog evHack in viewDidLoad. If you get nil back, it's not hooked up right.

Objective C / iPhone - how to bind UISlider to code

I'm just starting with Objective C, but I'm already running into a problem:
When I did this in the past, I had no problem with it:
I made a new UISlider, clicked it, CTRL dragged a blue line to the code, and somehow I was then able to read it's values.
However, I am now running into the problem that I can't draw those lines anymore.
By messing around I managed to get buttons to work, but the slider just won't work.
my Mainwindow.xib has got the iSaturateViewController class,
iSaturateViewController.xib has got the whole interface in it.
How can I get the UISlider to work without being able to draw that line?
How I have it now:
(in iSaturateViewController.h)
#import <UIKit/UIKit.h>
#interface iSaturateViewController : UIViewController {
UISlider * satSlider;
UILabel * satLabel;
}
#property (nonatomic, retain) IBOutlet UISlider * satSlider;
#property (nonatomic, retain) UILabel * satLabel;
-(IBAction) changeSaturation:(id) sender;
#end
(in iSaturateViewController.m):
#synthesize satLabel,satSlider;
-(IBAction) changeSaturation:(id)sender {
satLabel.text = [[NSString alloc] initWithFormat:#"Saturation: %d ", (Float32)satSlider.value];
NSLog(#"%f", satSlider.value);
}
Ath the moment the NSLog shows: 0.00000000
Also, I've set the Label in the Identity properties to: satSlider (slider) and satLabel (label).
Just to clarify my goal:
I want the slider's (satSlider) value to show in the UILabel (satLabel) via the function changeSaturation.
How can I do this?
Add the method declaration:
-(IBAction) changeSaturation:(id)sender;
to the header file iSaturateViewController.h
Then, assign the Value Changed action of your UISlider to your changeSaturation method. Right click on the slider and drag the Value Changed to the File's Owner and connect them. It should work.
You can also try this:
-(IBAction)changeSaturation:(id)sender {
UISlider *slider = (UISlider *)sender;
satLabel.text = [NSString stringWithFormat:#"Saturation: %f", slider.value];
NSLog(#"Saturation: %f", slider.value);
}
Regarding UILabel - add IBOutlet and connect it in the Interface Builder. The interface should be like that:
#import <UIKit/UIKit.h>
#interface iSaturateViewController : UIViewController {
IBOutlet UISlider * satSlider;
IBOutlet UILabel * satLabel;
}
#property (nonatomic, retain) IBOutlet UISlider * satSlider;
#property (nonatomic, retain) IBOutlet UILabel * satLabel;
-(IBAction) changeSaturation:(id) sender;
#end
Let me know if it works.
Looks like the key thing you’re missing is that the satSlider outlet isn’t hooked up, so its value is nil. You connected the slider’s action to the -changeSaturation: method, but it sounds like you didn’t also connect the satSlider property to the slider itself. Sending a message (like value in this case) to nil doesn’t do anything, and returns 0, so 0 is the value you’re getting out of it. Hook up your outlet by Ctrl-dragging from the property in the code to the slider in your UI and it should work.
You need to edit your header and add the method declaration. Then in IB, associate the first responder for value changed to the UISlider. Also slider.value, you need to read article: Setting interval value for UISlider

How to correctly detect touches in my UIView?

I'm having a problem. I have a UIView, that looks like this :
In that view controller I implemented the "touchesBegan:withEvent:" method, but the method is only getting triggered when I touch the bar at the bottom of the view , nothing happens when I touch the table.
How could I change this behavior to be able to detect the touches that occur in the table too ?
This is the code that basically declares that UIViewController:
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#interface TripSearchDetailViewController : UIViewController
{
//Parent of this sub-view.
UIViewController *parentController;
//GUI elements
UITableView *tableView;
UIButton *backButton;
}
//Button actions
- (IBAction) goBack:(id) sender;
- (IBAction) showDatePicker:(id) sender;
//Class Methods.
- (void) presentDatePicker;
#property (nonatomic, retain) UIViewController *parentController;
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) IBOutlet UIButton *backButton;
#end
It looks like you've got a UITableViewController, not a UIViewController. Your table view is intercepting and handling touches before they make it up to your view controller. You'll need to subclass UITableView, override it's -touchesBegan:withEvent: method, and then create a standard UIViewController that adds your new subclass to the view hierarchy.
I think it could possibly help to implement the method hitTest:withEvent: in your TripSearchDetailViewController. If you just return true in this method your touch should be recognized.
see also: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html