小编FRE*_*405的帖子

iOS快速代理在uiview中有超过1个uitextfield

我有一个iOS应用程序,有一个UIView和三个UITextField(超过1个)我想了解我的类ViewController管理的最佳实践 UITextField.

- 类MainViewController:UIViewController,UITextFieldDelegate

我不知道,因为我有一个以上UITextField,只有一个func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool

ios uitextfielddelegate swift

4
推荐指数
1
解决办法
4895
查看次数

模型与控制器之间的通信

从许多不同来源阅读后,我对View和Model应如何在MVC中与Swift进行通信感到非常困惑

如何用Swift做同样的事情(这里是Objective-c)

在模型中:

(void)receivedMessageFromServer {
    // Fire the notification
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedData" object:nil];   
} 
Run Code Online (Sandbox Code Playgroud)

在View Controller中处理"ReceivedData"通知:

(void)viewDidLoad {
    [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedDataNotification:) name:@"ReceivedData" object:nil];
}

-(void)receivedDataNotification:(id)object {
    NSLog(@"Received Data!");
}
Run Code Online (Sandbox Code Playgroud)

model-view-controller ios swift

2
推荐指数
1
解决办法
1946
查看次数