Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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/8/design-patterns/2.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_Delegates_Three20_Uitableview_Observer Pattern - Fatal编程技术网

Objective c 单击数据源中的按钮时如何调用函数?目标-C

Objective c 单击数据源中的按钮时如何调用函数?目标-C,objective-c,delegates,three20,uitableview,observer-pattern,Objective C,Delegates,Three20,Uitableview,Observer Pattern,我的问题似乎很简单,但我找不到答案。我在TableItemCell子类中创建了一个UiSwitch,我希望他从我的tableviewcontroller中调用一个函数(在我的例子中是discover),该函数是instatitate 如何从TableItemCell的子类访问此函数 这是我的代码: @implementation CCSettingsTableItemCell @synthesize idSetting; //Overriding cell - (id)initWithStyl

我的问题似乎很简单,但我找不到答案。我在TableItemCell子类中创建了一个UiSwitch,我希望他从我的tableviewcontroller中调用一个函数(在我的例子中是discover),该函数是instatitate

如何从TableItemCell的子类访问此函数

这是我的代码:

@implementation CCSettingsTableItemCell
@synthesize idSetting;

//Overriding cell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {
    if ((self = [super initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:identifier])) {
        switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
        self.accessoryView = switchView;
        [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
        [switchView release];
    }
    return self;
}

- (void) switchChanged:(id)sender {
    UISwitch* switchControl = sender;

    /////////////////////////////////////////////////////////
    //Here i want to call my function from my main controller

}
我的主控制器代码如下:

@implementation SettingController

///////////////////////////////////////////////////////////////////////////////////////////////////
// private

// This is the function i want to call
- (void)dismiss {
    [self dismissModalViewControllerAnimated:YES];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    random code;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// TTTableViewController

- (void)loadView {
    random code;
}

- (void)createModel {
    self.dataSource = [SettingControllerDataSource viewDataSource];

    // If dataSource nil, show an empty Message
    if (self.dataSource == nil) {
        [self showEmpty:YES];
    }
}

@end
说明:数据源添加了我的customcell类型CCSettingsTableItem的对象

任何帮助或提示都会很好

  • 您可以使用@protocol声明您的“disclose”方法,该方法由您的SettingController实现。将SettingController类与CCSettingsTableItemCell一致

  • 否则,在CCSettingsTableItemCell的.h文件中创建SettingController的对象。使用此对象可调用“discouse”方法


  • Nha i使用通知和观察者模式。它更合适。谢谢你的回答:)