Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joserskid

macrumors newbie
Original poster
Dec 30, 2011
20
0
I have a simple app I'm trying to make, and need some assistance (I'm new :D)

Heres what I have so far:

ViewController.m
Code:
@implementation ViewController
@synthesize textSize;

-(IBAction)hello:(id)sender{
    label.text =@"Sexy Beast ;)";
}
-(IBAction)food:(id)sender{
    label.text =@"Bacon :P";
}
-(IBAction)size:(id)sender{
   // NSString *textSize = [sender value:slider];
}

ViewController.h
Code:
@interface ViewController : UIViewController{
    IBOutlet UILabel *label;
    IBOutlet UISlider *slider;
}

@property (nonatomic ,retain) IBOutlet UILabel *textSize;

-(IBAction)hello:(id)sender;
-(IBAction)food:(id)sender;
-(IBAction)size:(id)sender;

@end

In general, I just want to get the slider value, and use that to set the size of the text label.
 
Change Text Size

You are trying to sett an NSString object equal to a slider value. That's not going to get you anything. Make sure your slider's min and max are at appropriate values, and that it's wired up to send the message "size". Then:

Code:
-(IBAction)size:(id)sender {

     float textSize = [sender floatValue]; // We get the value of the slider

     hello.font = [UIFont fontWithName:@"Helvetica" size:textSize]; // Change the text size of the labels
     food.font = [UIFont fontWithName:@"Helvetica" size:textSize];
}

You can use any font you want though.
 
I'm getting a SIGABRT error now :/

It's saying local declaration of 'text size' hides instance variable.
 
That error means that in your .h file you've declared an instance variable (aka "ivar") with the same name as a local variable, in this case, "textSize". You should probably delete the declaration of "textSize" in your .h file (unless you need it for some other reason... in which case maybe use separate names for the instance variable and local variable.)
 
I'm getting a SIGABRT error now :/

It's saying local declaration of 'text size' hides instance variable.

Sounds to me like your mixing things up. The "'text size' hides instance variable" would be a warning during compile time, or in the editor in Xcode 4. Due to variable scope rule, what that is saying is that your ivar version of that variable will not be used in that line.

The SIGABRT error is something that happens during app execution. You may get a hint of where that crash is occurring. Perhaps a line number.

P.S. Be precise with your warning and error lines. The above one is not correct. Given your posted code, I'd expect it to be "Local declaration of 'textSize' hides instance variable.". Your posted code is sparse too not to mention the ivar you mention is commented out.
 
Such a rookie mistake on my part, sorry!
Glad you understood without my posting the exact error.

I got rid of that error by deleting the @synthesize and the declaration in the header.
However, when I go to move the slider in the simulator, it still gives this:
Code:
@autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }

Thread 1: Program received signal: "SIGABRT"

The second line of the code is what is highlights and gives the SIGABRT error. (It's in the main.m file)

I should probably ask this. How do I link the slider to the variable textSize? Is there anything I should drag onto the view controller and connect with the storyboard? If I don't theres no error but also no text size change. If I drag from 'Value Changed' onto the view controller and connect it to 'size: ' it returns this error when I simulate and touch the slider. Sorry guys, fairly new to this :p
 
Last edited:
So, you've removed the textSize property from your code, right? Did you remember to remove the connection in your storyboard?

And does your size: method still contain:
Code:
-(IBAction)size:(id)sender{
   // NSString *textSize = [sender value:slider];
}
or something else now?
 
Nope I took that line out, and I took out the connection in Xcode. I'll just put what I have now.

ViewController.h:
Code:
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    IBOutlet UILabel *label;
    IBOutlet UISlider *slider;
}

-(IBAction)hello:(id)sender;
-(IBAction)food:(id)sender;
-(IBAction)size:(id)sender;

@end

ViewController.m
Code:
#import "ViewController.h"

@implementation ViewController

-(IBAction)hello:(id)sender{
    label.text =@"Sexy Beast ;)";
}
-(IBAction)food:(id)sender{
    label.text =@"Bacon :P";
}
-(IBAction)size:(id)sender{
    float textSize = [sender floatValue];
    label.font = [UIFont fontWithName:@"Arial" size:textSize];
}
 
Well now there isn't any errors, but it doesn't work at all.

I'm just not seeing how this:
float textSize = [sender floatValue];

gets the value of the slider? it doesn't even make reference to the slider at all.
I think I just don't know exactly what to connect in the story board interface.

EDIT: I think I have everything right now :/
it just gives that SIGABRT error every time I change the value of the slider.
 
Last edited:
I'm just not seeing how this:
float textSize = [sender floatValue];

gets the value of the slider? it doesn't even make reference to the slider at all.
sender is the reference to the slider. I was suggesting step-through debugging in hope you would come to this realization. But you want to cast it as such. I would do this:
Code:
UISlider *slider = (UISlider *)sender;
Then you can start to use the instance methods on your slider without compiler warnings.

EDIT: I think I have everything right now :/
it just gives that SIGABRT error every time I change the value of the slider.
Well, if you're still getting an error, I wouldn't say you have everything right. Again, step-through debugging will be the quickest way to determine where the issue is.
 
Code:
UISlider *slider = (UISlider *)sender;
I don't know where you'd put that.

Well, if you're still getting an error, I wouldn't say you have everything right. Again, step-through debugging will be the quickest way to determine where the issue is.

I have no clue how to step through debug :/
And I get the error when I change the slider value.
I know the error occurs here
Code:
label.font = [UIFont fontWithName:@"Arial" size:textSize];

It can't change it or won't for some reason.
 
Last edited by a moderator:
Finally found the error:

Code:
2012-01-03 12:28:30.696 helloWorld[1949:f803] -[UISlider floatValue]: unrecognized selector sent to instance 0x6b6d0d0
2012-01-03 12:28:30.698 helloWorld[1949:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISlider floatValue]: unrecognized selector sent to instance 0x6b6d0d0'
*** First throw call stack:
(0x13b9052 0x154ad0a 0x13baced 0x131ff00 0x131fce2 0x205c 0x13baec9 0x135c2 0x1355a 0xb8b76 0xb903f 0x140467 0xb7d86 0x3893f 0x38c56 0x1f384 0x12aa9 0x12a3fa9 0x138d1c5 0x12f2022 0x12f090a 0x12efdb4 0x12efccb 0x12a2879 0x12a293e 0x10a9b 0x1ca8 0x1c05)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c
(gdb)
 
You'd put it in your IBAction method, right before you want to start calling instance methods on your slider.


What kind of debugging do you know how to do? Where did you learn about it?

I don't know any kind of debugging :p
This is my first project in Xcode. I'm doing it to learn a little bit.
My understanding of the code has majorly increased by doing this btw ;D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.