English 中文(简体)
保持MVC清洁,以方案书面观点
原标题:Keeping MVC clean with a programmatically written view

i 急于从方案角度撰写我的分观点,原因是,我想要把冰带上布顿的图像。 因此,我写了我的文.和我的文.,用直截了当的方法看待:

- (id)init 
{
  if (self = [super init]){
    redBlack = [UIImage imageNamed:@"redB.png"];
    redWhite = [UIImage imageNamed:@"redW.png"];

    redButton = [UIButton buttonWithType:UIButtonTypeCustom];
    redButton.frame = CGRectMake(20.0, 30.0, 130.0, 130.0);
    [redButton setBackgroundImage:redBlack forState:UIControlStateNormal];
    [redButton setBackgroundImage:redWhite forState:UIControlEventTouchDown];
    [redButton addTarget:self action:@selector(controller.colorButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [redButton setTag:0];
    [self.view addSubview:redButton];
.....

The Problem is, that colorButtonPressed is a Method, which is written in my ControllerView-Singleton. I don t know if i am doing this right, but actually i wanted to keep the MVC as clean as possible. Is it a common way to do it like this and if so, the compiler doesnt let me write controller.colorButtonPressed: in @selector ?!? Or should i specify the programmatically written view also in my controller class?

Hopefully these questions dont sound too stupid!?
And thanks in advance!

最佳回答

 [redButton addTarget:self action:@selector(controller.colorButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

应当:

 [redButton addTarget:controller action:@selector(colorButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
问题回答

指标必须是方法界定的类别。

如果目标被定为“自己”,那么该方法应属于同一类别。 根据你的法典,这种方法在控制器中,这意味着该目标应是“控制器”,而选择者应为@selector(colorButtonPressed:)





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签