草庐IT

objective-c - 如何引用子类的父 View Controller ?

在这里你可以看到我已经将我的子类textView的委托(delegate)设置为它自己:importFoundationclassImageCaptionTextView:UITextView,UITextViewDelegate{overridefuncawakeFromNib(){super.awakeFromNib()delegate=self}现在在我的Controller中,我的委托(delegate)方法不起作用。我正在使用ImageCaptionTextView子类中的所有ImageCaptionTextView委托(delegate)方法,而不是它们以前所在的位置,即C

class - 在子类中覆盖返回协变类型的下标

我有一个类叫做LLLinkedList,它定义了一个subscript:classLLLinkedList{//otherproperties,functionsandinitializers...subscript(range:Range)->LLLinkedList{get{//returnsomething}set{//setsomething}}}现在subscript显然需要Range并返回LLLinkedList.我还定义了LLLinkedList的子类称为LLArray:classLLArray:LLLinkedList{//otherproperties,functio

ios - 子类化 MKAnnotation 错误,符合协议(protocol)

我查看了其他关于子类化的堆栈溢出问题的代码和片段。我想要做的就是子类化MKAnnotation。我正在使用Xcode6.3。此代码适用于我friend的,但不适用于我的。我收到一个Type'Annotation'doesnotconformtoprotocol'MKAnnotation'错误importFoundationimportMapKitimportUIKitclassAnnotation:NSObject,MKAnnotation{varlocation:CLLocationCoordinate2Dvartitle:Stringvarsubtitle:Stringinit(l

ios - 子类化时避免违反 LSP

在objective-C中,我可以子类化一个ViewController,如下所示。classKeyboardObserverViewController:UIViewController{vartableView:UITableView?init(){super.init(nibName:nil,bundle:nil)NotificationCenter.default.addObserver(self,selector:#selector(KeyboardObserverViewController.keyboardDidShow(_:)),name:NSNotification.

ios - Swift:子类 MKPolyline

我正在开发一个请求多个方向(MKDirectionsRequest)并在mapView中绘制路线的应用程序,一切正常。但我面临一个问题:我想用不同的颜色绘制每条路线。第一个想法很简单:使用标题/副标题来“标记”不同的MKPolyline,这样我就可以在委托(delegate)函数中设置我想要的颜色:mapView(_mapView:MKMapView,rendererForoverlay:MKOverlay)->MKOverlayRenderer但我不喜欢这个解决方案,因为它“丑陋”,而且我将不得不在必须传递不同参数(交通..)的那一天解析一个字符串第二个简单的解决方案是将MKPoly

ios - 检查 UICollectionViewCell 子类中的变量是否为 nil

我有这个UICollectionViewcellfunccollectionView(_collectionView:UICollectionView,cellForItemAtindexPath:IndexPath)->UICollectionViewCell{letcell=collectionView.dequeueReusableCell(withReuseIdentifier:cellId,for:indexPath)as!PostCellifletCurrentPost=posts[indexPath.row]as?Post{if(CurrentPost.PostImage

ios - 从父级获取子类

我在Swift编程方面遇到了一个大问题。我正在尝试从父级获取子类的名称。这是一个示例,我想做什么:classParent{classfuncsayHello(){letnameChildClass=//println("hi\(nameChildClass)")}}classMother:Parent{}classFather:Parent{}Mother.sayHello()Father.sayHello()我知道还有其他方法可以做到这一点,但我真的需要这样做。 最佳答案 您可以使用这样的函数:funcgetRawClassNam

Swift:从父类(super class)返回子类类型的对象数组

我有一个Swift类作为我应用程序中其他类型对象的基类。该类用于数据建模,因此它实现了各种功能来保存和从存储中检索对象。为了示例,我的类如下所示:classBase:NSObject{classfuncobjects()->[Base]{return[]}}基类的子类如下所示:classSubclass:Base{}这很好用,因为我可以创建子类的实例,然后获取对象数组:letobjects=Subclass.objects()但是,返回的数组设置为[Base]类型。有什么方法可以让Subclass.objects()自动返回一个[Subclass],而无需在子类中编写任何额外的代码?我

ios - 从子类在 Swift 中具有泛型的基类转换子类

我有一个基类类型和一个子类类型,其中子类包括一个泛型类型。如果我将子类以基类类型的形式存储,但我想将其类型转换回子类类型,Swift似乎不会让我这么做。下面是我的意思的一个例子:classBase{}classNext:BasewhereT:UIView{varview:Tinit(view:T){self.view=view}}leta:[Base]=[Next(view:UIImageView()),Next(view:UILabel())]foritemina{iflet_=itemas?Next{print("Hey!")}}为什么"Hey!"从未被打印出来?编辑:"Hey!"

ios - UIBezierPath子类初始化器

我正在尝试创建UIBezierPath的子类,以添加一些对我有用的属性。classMyUIBezierPath:UIBezierPath{varselectedForLazo:Bool!=falseoverrideinit(){super.init()}/*CompileError:Mustcalladesignatedinitializerofthesuperclass'UIBezierPath'*/init(rect:CGRect){super.init(rect:rect)}/*CompileError:Mustcalladesignatedinitializerofthesup