Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIButton无-IOS_Iphone_Ios_Uibutton - Fatal编程技术网

Iphone UIButton无-IOS

Iphone UIButton无-IOS,iphone,ios,uibutton,Iphone,Ios,Uibutton,我的viewdidload中有以下内容: //Start/Pause Button UIButton *buttonStart = [UIButton buttonWithType: UIButtonTypeCustom]; buttonStart.frame = CGRectMake(10,100,100,45); [buttonStart setBackgroundImage:[UIImage imageNamed:@"pause.png"] forS

我的viewdidload中有以下内容:

    //Start/Pause Button    
    UIButton *buttonStart = [UIButton buttonWithType: UIButtonTypeCustom];
    buttonStart.frame = CGRectMake(10,100,100,45);
    [buttonStart setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [buttonStart addTarget:self action:@selector(pausePlayButtonTouched) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview: buttonStart];
我的选择器方法:

   [self.buttonStart setBackgroundImage:[UIImage imageNamed:@"start.png"] forState:UIControlStateNormal];

    NSLog(@"%@", self.buttonStart);
正在将null记录到控制台。不用说,按钮的图像没有改变

我的想法怎么了


顺便说一句,buttonStart正在合成中,并且有自己的属性(retain)

您同时使用的是通过属性访问的实例变量
self.buttonStart
和局部变量
buttonStart
。从实现文件中删除该按钮的声明,并将第一行更改为:

self.buttonStart = [UIButton buttonWithType: UIButtonTypeCustom];

您是否在任何地方指定self.buttonStart?你是说

 self.buttonStart = [UIButton buttonWithType: UIButtonTypeCustom];
而不是

  UIButton *buttonStart = [UIButton buttonWithType: UIButtonTypeCustom];

您应该从文件名中删除“.png”标记,即“pause”,而不是“pause.png”。

buttonStart不需要属性。添加如下目标:

     [buttonStart addTarget:self action:@selector(pausePlayButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
现在,您选择的方法是:

-(void)pausePlayButtonTouched:(id)sender
{
   UIButton *btnPaused = sender;
   NSLog(@"%@", btnPaused);
   [btnPaused setBackgroundImage:[UIImage imageNamed:@"start.png"] forState:UIControlStateNormal];
}

据我所知,buttonStart的任务缺失了

您是否设置了self.buttonStart=buttonStart


声明UIButton*buttonStart=。。。将阴影(在本地上下文中)由@property(非原子,reatin)UIButton*buttonStart创建的任何已创建成员;(如果您使用LLVM 4.0+您的属性声明将创建“UIButton*\u buttonStart”作为成员)

这是不正确的,没有任何效果。扩展名(如果省略)将由系统自动添加。如果没有省略扩展名,它将按原样工作。@Till:并且如果我们将.png?+1作为一个有效的替代项,防止使用实例变量,那么retina(at)2x magic也会工作。