Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:22:58+00:00 2026-05-28T19:22:58+00:00

I’m new to objective-c programming and I stuck. I have uislider in my viewcontroller

  • 0

I’m new to objective-c programming and I stuck.
I have uislider in my viewcontroller and float variable in header file of viewcontroller.
I also have a new class which changes look of my second view, I overwritten drawRect.

I simply take value of slider.value and save it in my float variable then I try to access float variable in my class because this variable defines width of lines which i want to draw.

header file of my view controller

@interface ViewController : UIViewController 
{
float lineWidth;
}

@property float lineWidth;
-(float)changingline;
@end

viecontroller.m //sliderForLine = UISlider

- (IBAction)valuechangedForLine:(UISlider *)sender 
{

float sliderValue = sliderForLine.value;
lineWidth = sliderValue;
[self changingline];

}
-(float)changingline
{   
NSLog(@"%f", lineWidth);

return lineWidth;
} 

NSLog says there is some value in lineWidth

class which specifies how the second UIView should looks like

#import "ViewController.h"

ViewController *oldView = [[ViewController alloc] init];
CGContextSetLineWidth(ctx, oldView.lineWidth);
NSLog(@"%f",oldView.lineWidth);

and here, in second class, NSLog says always 0.

I’m confused, I don’t even know now why I’m using -(void)changeling 🙂

All I know is that I’m missing the main point how to pass values between classes, can somebody explain me what I’m doing wrong?

Thanks in advance :]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:22:59+00:00Added an answer on May 28, 2026 at 7:22 pm

    You NEED (not want) a delegate for this. Try something like this:

    header file of my view controller

    @protocol ViewControllerDelegate <NSObject>
    
    @required
    
    -(void)valueChanged:(float)value;
    
    @end
    
    @interface ViewController : UIViewController 
    {
    float lineWidth;
    id<ViewControllerDelegate> _delegate;
    }
    
    @property float lineWidth;
    @property (nonatomic, assign) id<ViewControllerDelegate> delegate;
    -(float)changingline;
    @end
    

    //.m

    @synthesize delegate = _delegate;
    ...
    
    - (IBAction)valuechangedForLine:(UISlider *)sender 
    {
    
    float sliderValue = sliderForLine.value;
    lineWidth = sliderValue;
    [self.delegate valueChanged:lineWidth];
    
    }
    

    Then all you need to do is conform to the protocol with a pair of these <> and implement the required method.

    Also, rename your iVar with an underscore (so, instead of lineWidth, use _lineWidth) then @synthesize lineWidth = _lineWidth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.