18

前のビューから「次へ」ボタンが押されたときに、新しいビューに UIButton のテキストを設定しようとしています。IBOutlet を正しく設定し、これに対する回答を探しましたが、まったく機能していません。

これが私がやろうとしていることのサンプルです:

- (IBAction)computeQuiz:(id)sender
{  
    [fiveFootUniversalResults setTitle:@"Test" forState:UIControlStateNormal];
}

- (IBAction)jumpT10ResultsView:(id)sender
{       
    NSString *nibFileToLoad = @"JumpT10Results";

    UIDevice *device = [UIDevice currentDevice];

    if([device userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        nibFileToLoad = [nibFileToLoad stringByAppendingString:@"-iPad"];
    }

    JumpmasterPathfinderViewController *nextView = [[JumpmasterPathfinderViewController    alloc] initWithNibName:nibFileToLoad bundle:nil];

    // Modal view controller
    nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nextView animated:YES];

    [nextView release];

    [scrollView setContentSize:CGSizeMake(imageViewWidth, imageViewHeight + 44.0)];
}

これらのアクションは両方とも、前のビューのボタンに接続されています。ビューは正常に読み込まれ、すべてが読み込まれます。唯一の問題は、ボタンのテキストが変更されないことです。IBOutlets が正しく設定されていることは 100% 確信していますが、何が間違っているのかわかりません。何か案は?

4

6 に答える 6

34

attributedTitleの代わりにIB が設定されているため、機能していませんtitle

代わりにこれを試してください:

NSAttributedString *attributedTitle = [self.myButton attributedTitleForState:UIControlStateNormal];
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithAttributedString:attributedTitle];
[mas.mutableString setString:@"New Text"];

[self.myButton setAttributedTitle:mas forState:UIControlStateNormal];

または、代わりに:

[self.myButton setAttributedTitle:nil forState:UIControlStateNormal];
[self.myButton setTitle:@"New Text" forState:UIControlStateNormal];

(2 番目のオプションでは、書式設定は保持されません。)

于 2013-11-26T20:03:18.463 に答える
3

このコードを試してください....

UIButton *backbtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 68, 38)];
[backbtn setTitle:@"Your string" forState:UIControlStateNormal];
//[backbtn setImage:[UIImage imageNamed:@"BackBtn.png"] forState:UIControlStateNormal];
[backbtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backbtn];
于 2011-12-16T10:59:35.850 に答える
1

電話してみる

- (IBAction)computeQuiz:(id)sender 

のメソッド

- (IBAction)jumpT10ResultsView:(id)sender

以下のコードのように、ボタン クリック時にメソッドを同時に呼び出すのではなく、メソッド me を呼び出すと、fiveFootUniversalResults ボタン オブジェクトが割り当てられません。

- (IBAction)computeQuiz:(id)sender
{  
    [fiveFootUniversalResults setTitle:@"Test" forState:UIControlStateNormal];
}

- (IBAction)jumpT10ResultsView:(id)sender
{       
    NSString *nibFileToLoad = @"JumpT10Results";

    UIDevice *device = [UIDevice currentDevice];

    if([device userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        nibFileToLoad = [nibFileToLoad stringByAppendingString:@"-iPad"];
    }
    JumpmasterPathfinderViewController *nextView = [[JumpmasterPathfinderViewController    alloc] initWithNibName:nibFileToLoad bundle:nil];

    // Modal view controller
    nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nextView animated:YES];

    [nextView release];

    [scrollView setContentSize:CGSizeMake(imageViewWidth, imageViewHeight + 44.0)];
    [self computeQuiz:nil];
}
于 2012-12-06T12:49:11.457 に答える
0

This can also happen if you forget to use the @synthesize on the button or variables related to it.

于 2013-04-04T03:29:52.293 に答える