Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Objective c 从控制器更新视图(目标c)_Objective C_Uiview_Uiviewcontroller_Uistoryboard - Fatal编程技术网

Objective c 从控制器更新视图(目标c)

Objective c 从控制器更新视图(目标c),objective-c,uiview,uiviewcontroller,uistoryboard,Objective C,Uiview,Uiviewcontroller,Uistoryboard,我的情况是这样的: 如果单击左脚按钮,我希望第二个控制器中的视图显示左脚图像,如果单击右脚按钮,视图应显示右脚图像 在第一个控制器中,我编写了以下命令来选择right或left: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { RSViewController *vc = [segue destinationViewController]; if ([[segue identifie

我的情况是这样的:

如果单击左脚按钮,我希望第二个控制器中的视图显示左脚图像,如果单击右脚按钮,视图应显示右脚图像

在第一个控制器中,我编写了以下命令来选择right或left:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    RSViewController *vc = [segue destinationViewController];

    if ([[segue identifier] isEqualToString:@"Left-Foot"])
        [vc setLeft:YES];
    else
        [vc setLeft:NO];
}
在第二个控制器中,我有一个设置布尔值的方法

- (void)setLeft:(BOOL)left
{
    if (left) {
        _left = left;
        NSLog(@"LEFT UPDATED IN RSVIEWCONTROLLER");
    }else {
        _left = left;
        NSLog(@"RIGHT UPDATED IN RSVIEWCONTROLLER");
    }
}
在同一个控制器中,我使用我的one init在viewdidload中创建了我的视图:

- (void)viewDidLoad
{
    NSLog(@"meeeea");
    [super viewDidLoad];
    CGRect rect = CGRectMake(0, 0, 100, 100);
    self.animatedCircleView = [[RSAnimatedCircleView alloc] initWithFrameFoot:rect foot:YES];
    NSLog(@"Viewdidnoload");
}
在我看来(图中的蓝色小矩形):

在方法“drawRect”中,leftfoot值始终为false。我不知道为什么会这样。。。有人能帮我吗


谢谢

您每次都在下一行中将视图设置为“左”

   self.animatedCircleView = [[RSAnimatedCircleView alloc] 
          initWithFrameFoot:rect foot:YES];
这是一个典型的错误,当没有给变量和方法提供可理解和直观的名称时,很可能会出现这种错误。如果你不改进你的方法,这种错误会经常发生

我将为您的视图提供一个枚举属性,明确说明它是什么:

typedef enum {LeftFoot, RightFoot} FootType; 
@property (strong, nonatomic) FootType footType; 
此外,还应该修改方法名称。我将完全取消
initWithFrameFoot
方法,只需在覆盖
initWithFrame
时设置一个默认的foot。(将其保留为0相当于
LeftFoot
)使用
@synthesis
您也不需要setter或getter。删除它们

如果需要专用的初始值设定项,请确保传递的变量前面有正确的单词

-(id) initWithFrame:(CGRect)rect andFootType:(FootType)footType {
    self = [super initWithFrame:rect]; 
    if (self) {
         _footType = footType;  
    }
    return self;
}
使用
@synthesis
后,您可以在
prepareforsgue:

footViewController.footType = rightFoot; 
footViewController.footType = rightFoot;