草庐IT

iphone - 声明委托(delegate)协议(protocol)

我想知道在同一个类中声明一个protocol和在一个单独的文件中声明它有什么区别;示例:#import@classMyClassA;@protocolMyDelegate@required-(MyClassA*)myMythod;@optional-(void)anOtherMethod:(NSString*)ID;@end@interfaceMyClassB:UIViewController@property(nonatomic,assign)iddelegate;......在这里,我在与MyClassB相同的文件中声明协议(protocol)委托(delegate),我可以在单独

iphone - 在没有任何导航 Controller 连接的情况下使用 View Controller 之间的委托(delegate)传递数据

有很多在两个ViewController之间传递数据的示例,其中一个ViewController导航到另一个ViewController。但是是否可以在未通过导航Controller连接的ViewController之间使用自定义协议(protocol)和委托(delegate)传递数据?因此,一个示例可能是:三个ViewController,即A、B、C。A导航到B,B导航到C。我知道如何使用自定义协议(protocol)和委托(delegate)在A和B之间传递数据。但是我们可以在C和A之间传递数据吗?因此A可以是C的委托(delegate),从而可以从C接收数据。这可能吗?如有任

ios - 选项卡栏确实选择了委托(delegate)方法在 ios 中给出了先前选择的选项卡索引,swift 3

我正在尝试实时检测用户选择了哪个选项卡。例如,如果用户选择0th索引,同时我想让该用户选择了zeroth索引选项卡。所以为此,我使用了如下所示的tabbarcontroller委托(delegate)方法。overridefunctabBar(_tabBar:UITabBar,didSelectitem:UITabBarItem){print("theselectedindexis:\(selectedIndex)")}但这显示了前一个ViewController。举个例子,假设我在secondtab中,然后我选择firsttab然后将索引打印为2.so我怎样才能得到正确的选择标签。希

iphone - iOS在调用方法之前检查委托(delegate)是否存在

我编写iOS应用程序并使用imageStore库延迟加载图像并将它们缓存在内存中。(https://github.com/psychs/imagestore)我在ViewController上创建图像存储实例:imageStore=[ImageStorenew];imageStore.delegate=self;图片加载成功后,imagestore调用委托(delegate)方法-(void)imageStoreDidGetNewImage:(ImageStore*)senderurl:(NSString*)url在tableview上执行reloadData以重绘单元格。一切正常。但

iphone - 在调用 respondsToSelector 之前检查委托(delegate)是否仍然存在

我制作了一个UIView子类来处理iAds和adMob。ViewController是子类委托(delegate),一切正常。然而,有时,ViewController会在获取广告之前消失。为了解决这个问题,我在ViewController的dealloc实现中将delegate设置为nil。我遇到的问题是,有时respondsToSelector:方法会在ViewController被释放的同时运行。这会导致崩溃。有谁知道我该如何重新安排这个?广告View在大约10个不同的ViewController上,所以我想要一个地方来创建广告代码。非常感谢 最佳答案

ios - 委托(delegate)成为噩梦的多层 subview Controller ——它们应该如何相互通信?

这对我来说是个严重的问题。在代码库上工作,多层subviewController大约有4-5层深-这是一款平板电脑应用程序,ViewController之间的解耦程度非常高。第5层subviewController想要向顶层ViewController发送消息以显示模态。第4层和第3层也有不同的消息,所以基本上现在我有4个协议(protocol),从嵌套在内部深处的subviewController向祖先ViewController发送消息变得非常复杂。有更简单的方法吗?我们考虑过使用NSNotification但并不是特别喜欢它,因为它很难调试,而且订阅不是我们控制范围内的明确依赖项

ios - searchBarTextDidBeginEditing 委托(delegate)方法调用了两次

我正在调试我的代码,每次我点击搜索栏(位于导航栏中)时,UISearchBar的委托(delegate)方法searchBarTextDidBeginEditing:被调用两次。奇怪的是只有这个委托(delegate)方法被调用了两次。其他的在整个过程中只被调用一次,这是正确的行为。-(BOOL)searchBarShouldBeginEditing:(UISearchBar*)searchBar{//calledonlyoncereturnYES;}-(void)searchBarTextDidBeginEditing:(UISearchBar*)searchBar{//called

ios - 实现嵌入在两个独立容器 Controller 中的 View 之间的委托(delegate)

我Storyboard的相关部分如下所示:您可以看到自定义“容器Controller”View包含两个容器View,一个通过嵌入式转场链接到导航Controller,另一个通过嵌入式转场链接到自定义“主视图Controller”(实现TableViewController)。NavigationController组件还与自定义“LocationFilterController”有关系。我需要实现委托(delegate),以便当位置过滤器Controller中的一个UIStepper是incr./decr.时,主视图Controller中的TableView知道相应地更新它显示的数据。

ios - NSURLSession 委托(delegate)和 completionHandler

我正在使用NSURLSession+NSURLDownloadTask和completionHandler:[sessiondownloadTaskWithURL:downloadURLcompletionHandler:^(NSURL*location,NSURLResponse*response,NSError*error)效果不错。但是当我想在progressBar中跟踪下载时,我遇到了问题。我正在尝试使用NSURLSessionDownloadDelegate来跟踪加载。对于上层的completionHandler,它永远不会被调用?!使用:NSURLSessionDownlo

ios - 在我们之前尚未在 GMSPlacePickerViewController 实例上设置委托(delegate)

我已经使用IOS和GoogleMapsApi玩了几天,两天前API升级到2.3版,不推荐使用GMSPlacePicker。Deprecationnotice:GMSPlacePickerNotice:Theimplementationoftheplacepickerhaschanged.Asofversion2.3oftheGooglePlacesAPIforiOS,theGMSPlacePickerclassisdeprecated,replacedbyGMSPlacePickerViewController.UseoftheGMSPlacePickerclasswillonlybe