UIButton style gone after segue - ios

I'm trying to fix a problem that does not make any sense to me.
I'm applying a style to 3 of my buttons. When I click another one, there is a segue. When I dismiss the viewController, the style is not applied to my 3 previous buttons..until I click again ! I thought it was my configuration with line code that was wrong so I've deleted every customizations.
I directly configure buttons from the interface builder.
Here it my segue code even if I think it's not useful.
- (IBAction)addContact:(id)sender {
[self performSegueWithIdentifier:#"FriendsToAddFriends" sender:sender];
}
I've added some picture to show my problem :
The strangest part is when I'm back to the first page, when I click without release my click, the style comes back. It's the same for the whole 3 buttons.
I don't have any other idea to fix it. Does someone have ?
Thank you a lot in advance !

Problem solved with this code :
for (UIButton* button in buttons) {
[button.titleLabel setTextAlignment:NSTextAlignmentNatural];
}
I applied it on each following methods :
viewWillDisappear
viewWillAppear
I still don't know why this alignment change when the view will disappear.
It seems working for now.
I hope it will help someone else.

Related

iOS IBAction with textDocumetProxy within a second ViewController (Objective-C)

I don't have a ton of experience with iOS development, but I feel like this should be possible. What I'm trying to do is do an IBAction within a second view controller. The IBAction is I'm trying to preform looks like this:
- (IBAction)helloWorldButton:(id)sender {
[self.textDocumentProxy insertText:#"Hello World"];
}
I've linked up the send event to touch up inside. I am able to pull up the second view controller and properly dismiss it with:
- (IBAction)dismissSecondView:(id)sender {
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
That all works fine which is what's confusing me. Why does the IBAction for dismissing the view controller work but the IBAction for textDocumentProxy doesn't? I can provide more code and information if needed, but I have successfully linked up the two view controllers to appear and be dismissed. I just want a button that types "Hello World" within the secondary view controller.
Thank you for your help in advance!
I figured it out. I was thinking about it all wrong. What I was looking to do was change the label on multiple buttons, not change the entire view. What I did was this:
Take the button to change the state of other buttons, and tell it tell it to change the buttons accordingly using
- (IBAction)buttonChanger:(id)sender {
if ([_aButton.titleLabel.text isEqual: #"Hello"]) {
[UIView setAnimationsEnabled:NO];
[_anotherButton setTitle:#"World" forState:UIControlStateNormal];
[_lastButton setTitle:#"Friend!" forState:UIControlStateNormal]; //more buttons after this...
Not sure if that example makes a ton of sense (changed the variables up a bit from the original project) but that will change each button accordingly. When I push button "Button Changer", it checks the status of "aButton" to see if anything needs changing, and then changes the title of the other buttons (anotherButton, lastButton) to World and Friend! accordingly. This is exactly what I was looking to do. I realize this is a completely different route to what I was initially thinking, but it works great!
Thanks for your help!

implementing textViewDidChange:

So, I have this very simple list project with objective-c, where every item on the list should have a title and a description. When clicking on one of the items, the detail view of the item shows up. The title, on the navigation bar is the item's title, and the rest of the view is the item's description. By clicking on the title, the user should be able to change it, and by clicking on the description they should also be able to change it.
Up until changing the title everything is going OK, I've managed to do that. The problem is when it comes to changing the description. I tried using the delegate, but I guess I must be using some command wrong, because it's simply not working. I tried looking for it online, but all I find are solutions for the TextField, which doesn't really help me, since I want to display a possibly multiline description, and I would rather not have to change from a TextView to a TextField every time the user wants to edit it. So if anyone could help me out with that, that would be awesome.
Here is the code where I try using the delegate.
on viewDidLoad I have this:
[self.descriptionLabel setDelegate:self.descriptionLabel.delegate];
and then I have this, where it should perform the actions after the text is changed:
- (void)textViewDidChange:(UITextView *)textView {
NSLog(#"Hello World");
}
P.S.: I was also looking for a way to have the "Done" button show up over the keyboard, because as of now, once the keyboard is brought up, the only way to get it down again is going back to the table view and then into the detail view again. I tried a couple of things already, but I'll admit that I wasn't too thorough on my research. So, as a side note, if you could show that too, it would be great, otherwise, the one thing I'm really after here is the question above. Thanks for any help! :]
Summary of answer based on the comments.
The line:
[self.descriptionLabel setDelegate:self.descriptionLabel.delegate];
needs to be:
self.descriptionLabel.delegate = self;
You want the view controller to be the delegate since the view controller implements the text view delegate methods.
You also need to indicate that the view controller conforms to the UITextViewDelegate protocol.
In your .m file, add the following:
#interface DetailViewController () <UITextViewDelegate>
#end

How to change labels text from a button on a CCScrollView?

I posted something very similar earlier, but I think the post was confusing so I'm redoing it.
Here's the setup. I am using SpriteBuilder. I have 2 CCB classes, MainScene.ccb and Scroll.ccb. The Scroll.ccb is a layer with a button on it. MainScene contains a CCScrollView and a CCLabelTTF. The CCScrollView is loading Scroll.ccb. The CCScrollView takes up half of the interface of MainScene, and on the other half is a CCColor that has the label on it.
When I click the button on the CCScrollView, I want the label on MainScene to change its text. The problem I am having is that the labels text doesn't change. However if I write an NSLog inside the buttons method to output text in the log, that DOES work.
I am including four pictures to help you better understand the situation.
http://imgur.com/a/77XyJ
I've been stuck on this for over a week now on my main project. I honestly have no clue what to do anymore, I've tried a bunch of things that didn't work, and I've run out of ideas.
EDIT: Okay so I got a little but further in debugging the issue. I inserted a label into the scrollview, and named it Label2. Under the buttons method I added 'Label2.string = #"Test"' and when I ran the program and clicked the button, the label on the scrollview changed. So it seems that when the button is being clicked, it looks in MainScene for the method and finds it, but it can't update a label on a different CCNode.
Do you have linked this method to the "click me" button ? Or maybe try to create a IBAction ?
-(void)testButton {
changeLabel.String = #"Changed !";
}
OR
- (IBAction)testButton:(id)sender {
changeLabel.String = #"Changed !";
}
i mean in your storyboard ( create the link with ctrl key and drag drop )
Hope this will help you.

Making a button invisible after clicking it?

I would like to know how to make a button that starts the gameplay and right after the gameplay starts the button must disappear from the view and can't be touchable.
Does anyone know how to do this?
you can also do it by setting its alpha value to zero. try this!
[self.buttonName setAlpha:0];
and again on changing it to one will unhide the button.
[self.buttonName setAlpha:1];
hope this serves your purpose. Happy coding!.
I think it is quite simple make sure you have both the outlet and Action property of UIButton. In the .h file.
#property(weak,nonatomic)UIButton *clickMeButton;
-(IBAction)clickMe:(id)sender;
Now implement the hide code in the .m file
-(IBAction)clickMe:(id)sender
{
clickMeButton.hidden=YES;
}
I hope this will work for you .

Adding a custom UIButton and action to a view in window app delegate (ios)

I am working on a tab bar application which needs a global title bar with a setttings button attached. I have achieved adding an imageview to the main window, then a label, another image, and finally a button. However, I cannot get this button to fire an action. it is set up like this:
[settingsButton addTarget:self action:#selector(settings) forControlEvents:UIControlEventTouchupInside];
Then the action defined like:
-(void)settings{
NSLog(#"please do something");
}
However nothing happens, the image doesn't even change like it is being pressed. Can i not define buttons in the app delegate this way? is it because the target is not something that is control based? i tried different targets but i must not fully understand what setting a target is. thanks for any help.
P.S.- i tried setting up the method like so as well:
-(void) settings:(id)sender{
}
and calling it by replacing the action with #selector(settings:) to no avail. Thank you.
I solved it. I forgot I changed the view behind the button to a UIImageView. I can't believe I didn't think of this before since this same issue cost me 2 hours the other day. When you have an imageView always remember to set this flag if you want stuff on it:
(someImageView).userInteractionEnabled = YES;
Hopefully I save someone an hour or two of needless headaches.
P.S. Thanks for the speedy comment !

Resources