Tag: 协议

使用委托更改标签文字颜色

我有两个视图控制器, ParentViewController有使用SecondViewController更新的标签。 现在我想从ChildViewController更改ParentViewController的标签文本颜色,因为我使用的协议和委托,但它显示错误。 我的代码是这样的: ChildViewController.h @protocol ViewControllerDelegate -(void) updateLabel; @end @interface ChildViewController : UIViewController<UITextFieldDelegate,UITextViewDelegate> { id <ViewControllerDelegate> delegate; } @property (assign) id <ViewControllerDelegate> delegate; @end ChildViewController.m @implementation childViewController @synthesize delegate; – (IBAction)backBtn:(id)sender { [delegate updateLabel]; } @end ParentViewController.h #import <UIKit/UIKit.h> #import "childViewController.h" @interface ParentViewController : UIViewController<UserResizableViewDelegate,ViewControllerDelegate> @end ParentViewController.m @implementation ParentViewController – (void)viewDidLoad { ChildViewController.delegate=self; //here […]

没有types或协议名称

在search了这个答案之后,我发现了许多相关的问题,但是在实现它们之后,我仍然无法摆脱这个错误。 我有一个AFHTTPRequestOperationManager类的类。 在导入语句结束之后,在这个类中的.h文件写了@protocol apiClientDelegate; 在@interface有一个@property (weak) id<apiClientDelegate>delegate; 之后我写了: @protocol apiClientDelegate <NSObject> @required -(void)finalImageURLs:(NSMutableArray*)array; @end 所以在另一个类,这是一个UICollectionViewController我已经写了@interface GalleryCollectionViewController : UICollectionViewController <apiClientDelegate> ,它仍然显示这个错误。 以下是截图: 并且在给出错误的类中: UPDATE 在添加了@protocol apiClientDelegate; 在GalleryCOllectionViewController但是现在它开始显示这个警告,并且该方法不被执行:

它如何才能迅速closures它的类的引用属性运行?

我有以下2个控制器列出如下。 我正在使用委托来尝试创build一个progressWindow,它将运行代码并很好地打印它,但代码是任意的。 闭包由符合协议的类定义(在我的情况下是SyncViewController), 但是我想从SyncViewControllers codeToRun {}闭包中更改progressWindowViewController的UI。 我该怎么做呢? SyncViewController.swift import UIKit class SyncViewController: UIViewController, progressWindowDelegate { var codeToRun = { //(self as! ProgressWindowViewController).theTextView.text = "changed the text" print("code to run") } var codeToCancel = {print("code to cancel")} var titleToGive = "Starting Sync…" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. […]

调用协议方法两次,Swift

我有从UITextFieldDelegate协议使用方法的子类文件 class MyTextField: UITextField, UITextFieldDelegate { . . . override func willMoveToSuperview(newSuperview: UIView?) { super.willMoveToSuperview(newSuperview) self.delegate = self } func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { // some actions return true } } 在我的ViewController类中,我使用input字段与我的子类 class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var field: MyTextFieldMask! override func viewDidLoad() { super.viewDidLoad() // […]

使用Swift协议时发生短路

众所周知,从-Header.h文件中包含接口头文件是不可能的。 我的实际问题是,我有一个类的协议是Swift的一个定义: @protocol arrivingDelegate; @interface palettaTraffic : NSObject<MKMapViewDelegate, arrivingDelegate> { } 如果我导入* -Swift.h文件,当文件被包含在头文件中包含的另一个文件中时,我进入了丑陋的循环。 当我使用@protocol指令时,会发生这种情况:这是一个警告,但相当令人不安。 这就是swift协议的定义: @objc public protocol arrivingDelegate { func submitManualBusLine(busStripe:StripeProtocol) } 我还发现一个类似的post: Objective-C类中的Swift协议 但是这些build议似乎都不适用。

Swift:委托协议没有正确设置UILabel

我有以下Protocol : protocol SoundEventDelegate{ func eventStarted(text:String) } 我在这堂课中所称的: class SoundEvent { var text:String var duration:Double init(text: String, duration: Double){ self.text = text self.duration = duration } var delegate : SoundEventDelegate? func startEvent(){ delegate?.eventStarted(self.text) } func getDuration() -> Double{ return self.duration //TODO is this common practice? } } 我有我的ViewController符合: class ViewController: UIViewController, SoundEventDelegate { //MARK:Properties @IBOutlet […]

调用另一个类的function(协议)

我有一个滑出导航面板(菜单)和另一个“菜单”在我的第一页。 滑出菜单: 指数 第1页 第2页 第3页 第4页 在索引: 第1页 第2页 第3页 第4页 因此,用户可以从索引或滑动(或点击图标菜单)访问页面以获得菜单。 但我有一个错误:我从索引页1,我点击图标菜单滑出菜单,我点击索引,我再次从索引页1,在这里,如果我再次点击图标菜单,我得到错误:SIGBRT(类似的东西) 我做了一些断点: 在这一行: self.delegate?.pushViewControllerInStack!(UIStoryboard.nosOffresViewController(‌​)!) 还有一个在函数pushViewControllerInStack 而当我做操纵,我的应用程序读取这行self.delegate?.pushViewControllerInStack!(UIStoryboard.nosOffresViewController(‌​)!)但它不会在function。 所以我的观点lost the accessfunctionlost the access ,但我不知道为什么以及如何解决这个问题。 有很多代码,你可以在这里find一个git仓库: https : //github.com/Vkt0r/SlideOutSideBarTest 错误: 2015-10-28 09:00:33.038 Solutis[477:5075] -[Solutis.NosOffresViewController menuNosOffresTapped:]: unrecognized selector sent to instance 0x7ff5caf464e0 2015-10-28 09:00:33.045 Solutis[477:5075] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Solutis.NosOffresViewController menuNosOffresTapped:]: […]

将generics应用于variables和函数 – Swift

我试图在swift中使用generics,以初始化Vector3D类中的variables。 然而,分配协议'数字'给我的variables(使其成为一个双或浮动),我得到以下错误: Protocol“Number”只能用作通用约束,因为它具有Self或相关types的要求 public protocol Number { func +(l: Self, r: Self) -> Self } extension Double : Number {} extension Float : Number {} class Vector3D: NSObject { var xCord: Number var yCord: Number var zCord: Number func Vector3D(x: [Number], y: [Number], z: [Number]) { self.xCord = x self.yCord = y self.zCord = z […]

如何从已经在UINavigationController栈中的UIViewController调用一个方法

我有一个UIViewController在UINavigationStack和从这个UIView我加载另一个视图不到堆栈,但作为子视图。 我加载的这个视图只是一个应用程序的首选项视图,我把它叠加到所展示的任何东西上。 即 myViewController <- on the stack button touch loads as a subview to myViewController + prefrencesViewController 我的问题是,有没有办法从prefrencesViewController调用myViewController中的方法? 我试图使用委托和协议,但它不工作,所以我希望有一个简单的方法来做到这一点,我不知道或者也许我可以得到一些帮助我的委托/协议… 这是我的代码看起来像委托和协议设置 //prefrencesViewController.h @protocol GetPrefrencesViewControllerDelegate <NSObject> -(void)reloadViewFromSavedPrefrences; @end //delegates and protocols @property (nonatomic, weak) id <GetPrefrencesViewControllerDelegate> delegate; //prefrencesViewController.m //delegates and protocols @synthesize delegate; //.. inside button action [[self delegate] reloadViewFromSavedPrefrences]; //myViewController.h #import "prefrencesViewController.h" @interface myViewController : […]

我可以分享Facebook user.name和user.id多个视图

我已经在这个项目上工作了几个月,我只编程了大约一年,所以即时通讯不会在这个问题上很聪明,所以请耐心等待,我已经创build了一个Facebooklogin,一旦我获取用户信息,我有创build了一个方法来parsing信息到login视图 我把这个方法放在 并且这个方法一旦接收到信息就会传递给loginViewController,我试着将相同的信息传递给settingViewController来显示名字和图片,这是user.name和user.id,我做了相同的步骤,并使用相同的步骤协议,它不工作,现在我的问题是,因为即时通讯使用的信息在loginViewController我不能放置或使用它们在settingViewController,因为即时通讯使用的信息已经。 你能帮我解决这个问题吗?我只是在上个月才开始使用协议。