Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 在ios中保留的属性_Objective C_Ios - Fatal编程技术网

Objective c 在ios中保留的属性

Objective c 在ios中保留的属性,objective-c,ios,Objective C,Ios,好的,简单的问题,但找不到答案 我需要将我的viewcontroller传递给一个类中的方法“saveinfo”,该方法在按下按钮时被调用,如何使viewcontroller对“saveinfo”方法可见,以便我可以在那里使用它 好的,我将添加整个类。基本上,我需要在按下按钮时获取文本字段信息。但我无法在saveinfo方法中访问textFields或TableControll变量 @implementation Settings - (id)init: (TableViewControlle

好的,简单的问题,但找不到答案

我需要将我的viewcontroller传递给一个类中的方法“saveinfo”,该方法在按下按钮时被调用,如何使viewcontroller对“saveinfo”方法可见,以便我可以在那里使用它

好的,我将添加整个类。基本上,我需要在按下按钮时获取文本字段信息。但我无法在saveinfo方法中访问textFields或TableControll变量

@implementation Settings

- (id)init: (TableViewController*) TableControll {
  NSMutableArray *textFields = [[NSMutableArray alloc] initWithCapacity:5];
    UITextField *textField = nil;

    for (int i = 0; i < 3; i++) {
        textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f+(i*35), 120.0f, 30.0f)];
        textField.backgroundColor = [UIColor whiteColor];
        [textField setBorderStyle:(UITextBorderStyleRoundedRect)];
        [TableControll.view addSubview:textField];

        [textFields addObject:textField];
        [textField release]; textField = nil;
    }
    UITextField *textName = textFields[0];
    textName.placeholder = @"Vardas";

    UITextField *textNo = textFields[1];
    textNo.placeholder = @"Telefonas";
    textNo.keyboardType = UIKeyboardTypeNumberPad;
    UITextField *textPin = textFields[2];
    textPin.keyboardType = UIKeyboardTypeNumberPad;
    textPin.placeholder = @"Pin";

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(150, 20, 160, 30);
    [button setTitle:@"Advanced settings" forState:UIControlStateNormal];
    [TableControll.view addSubview:button];
    UIButton *save = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    save.frame = CGRectMake(150, 60, 160, 30);
    [save setTitle:@"Save settings" forState:UIControlStateNormal];
    [TableControll.view addSubview:save];
    [button addTarget:self action:@selector(goAdvanced)
     forControlEvents:UIControlEventTouchUpInside];
    [save addTarget:self action:@selector(saveInfo)
     forControlEvents:UIControlEventTouchUpInside];

    return self;
}

-(void)goAdvanced {
    AppDelegate *newControll = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [newControll ChangeController];
}

-(void)saveInfo {

    for(int i=0;i<5;i++) {
        UITextField *tempTxtField=[_textFields objectAtIndex:i];
        NSLog(@"do it %@",tempTxtField.text);
    }

}

@end
@实现设置
-(id)init:(TableViewController*)TableControll{
NSMUTABLEARRY*textFields=[[NSMUTABLEARRY alloc]initWithCapacity:5];
UITextField*textField=nil;
对于(int i=0;i<3;i++){
textField=[[UITextField alloc]initWithFrame:CGRectMake(0.0f,0.0f+(i*35),120.0f,30.0f)];
textField.backgroundColor=[UIColor-whiteColor];
[textField setBorderStyle:(UITextBorderStyleRoundedRect)];
[TableControll.view addSubview:textField];
[textFields addObject:textField];
[textField release];textField=nil;
}
UITextField*textName=textFields[0];
textName.placeholder=@“Vardas”;
UITextField*textNo=textFields[1];
textNo.placeholder=@“Telefonas”;
textNo.keyboardType=UIKeyboardTypeNumberPad;
UITextField*textPin=textFields[2];
textPin.keyboardType=UIKeyboardTypeNumberPad;
textPin.placeholder=@“Pin”;
UIButton*button=[UIButton button类型:UIButtonyPeroundRect];
button.frame=CGRectMake(150,20,160,30);
[按钮设置标题:@“高级设置”用于状态:uicontrol状态正常];
[TableControll.view添加子视图:按钮];
UIButton*save=[UIButton按钮类型:UIButtonTypeRondRect];
save.frame=CGRectMake(150,60,160,30);
[保存设置标题:@“保存设置”用于状态:UIControlStateNormal];
[TableControll.view addSubview:save];
[按钮添加目标:自我操作:@selector(goAdvanced)
forControlEvents:UIControlEventTouchUpInside];
[保存添加目标:自我操作:@选择器(保存信息)
forControlEvents:UIControlEventTouchUpInside];
回归自我;
}
-(无效)goAdvanced{
AppDelegate*newControll=(AppDelegate*)[UIApplication sharedApplication]。委托;
[新控制器更改控制器];
}
-(作废)保存信息{

对于(int i=0;i只需将
NSMutableArray
作为ivar添加到类中:

@implementation TableControll {
    NSMutableArray *_textFields;
}

- (id)init: (TableViewController*) tableControll {
    _textFields = [[NSMutableArray alloc] initWithCapacity:5];

    //init the textfields
    //and add it as subview
}

// skipping the rest of the implementation

-(void)saveInfo {
    for(int i=0;i<5;i++) {
        UITextField *tempTxtField=[_textFields objectAtIndex:i];
        NSLog(@"do it %@",tempTxtField.text);
    }                 
}  
@end
@implementation TableControll{
NSMutableArray*_文本字段;
}
-(id)init:(TableViewController*)tableControll{
_textFields=[[NSMutableArray alloc]initWithCapacity:5];
//初始化文本字段
//并将其添加为子视图
}
//跳过其余的实现
-(作废)保存信息{

对于(int i=0;我给我们一些更多的信息:应用程序的结构是什么?控制器A->B类还是它们在2类中不相关?您的主控制器是什么?它是否保留您需要的控制器?