AlgoCoder
AlgoCoder

Reputation: 1696

Changing button text is not working iOS

I've dragged a button using storyboard and created IBoutlet for it in .h file also synthesised it.

Now i'm trying to change the text of the button but it is not working for me.

- (id)initWithCoder:(NSCoder *)decoder
{
    if ((self = [super initWithCoder:decoder])) 
    {
        configDetails *updatedConfig=[[configDetails alloc]init];
        [updatedConfig setAllItemstext:@" Go to AllItems"];
        [updatedConfig setAboutUstext:@"Text for AboutUs button"];
        [updatedConfig setHomeScreenTitleColor:@"Yellow"];

        NSString *newtext=[updatedConfig aboutUstext];
        NSLog(@"%@",newtext);
        [aboutUs setTitle:[updatedConfig aboutUstext] forState:UIControlStateNormal];

        [allItems setTitle:[updatedConfig allItemstext] forState:UIControlStateNormal];
    }

return self;
}

Upvotes: 0

Views: 150

Answers (2)

johnMa
johnMa

Reputation: 3311

You can't set your IBOutlet properties in initWithCoder method .

See my answer about this

Upvotes: 0

Hussain Shabbir
Hussain Shabbir

Reputation: 15015

Try like this write your code into viewDidAppear:-

-(void)viewDidAppear:(BOOL)animated{
  configDetails *updatedConfig=[[configDetails alloc]init];
    [updatedConfig setAllItemstext:@" Go to AllItems"];
    [updatedConfig setAboutUstext:@"Text for AboutUs button"];
    [updatedConfig setHomeScreenTitleColor:@"Yellow"];

    NSString *newtext=[updatedConfig aboutUstext];
    NSLog(@"%@",newtext);
    [aboutUs setTitle:[updatedConfig aboutUstext] forState:UIControlStateNormal];

    [allItems setTitle:[updatedConfig allItemstext] forState:UIControlStateNormal];
[super viewDidAppear:animated];
}

Upvotes: 1

Related Questions