Tag: 子类

使用WKWebView创build自定义ORKStep

我对iOS开发比较陌生,目前使用Swift来开发一个原型的ResearchKit应用程序。 其中一个要求是在一个WKWebView中embedded一个WKWebView ,包含三个步骤: ORKQuestionStep , ORKWebViewStep , ORKCompletionStep 。 我似乎无法find关于如何使用Swift子类化ORKStep和ORKStepViewController创build自定义步骤的很多信息。 有人可以指导我正确的方向如何子类ORKStep和ORKStepViewController显示使用Swift的WKWebView ? 先谢谢你!

UITableViewCell子类

我有这个代码段: if (cell == nil) { CGRect cellFrame = CGRectMake(0,0,300,250); cell = [[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:CellTableIndetifier]; CGRect nameLabelRect = CGRectMake(0, 5, 70, 20); UILabel* nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect]; nameLabel.textAlignment = NSTextAlignmentCenter; nameLabel.text = @"Name"; nameLabel.font = [UIFont boldSystemFontOfSize:12]; [cell.contentView addSubview: nameLabel]; CGRect colorLabelRect = CGRectMake(0, 25, 70, 20); UILabel* colorLabel = [[UILabel alloc] initWithFrame:colorLabelRect]; […]

当在两个嵌套子类中调用super.viewDidLoad()时,我得到了Swift无限循环

我正在编写一个用Swift编写的iOS应用程序。 我有一个UITabBarController的子类,然后是一个嵌套的子类: class HWTabBarController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() … } } class MainTabBarController: HWTabBarController { override func viewDidLoad() { super.viewDidLoad() … } } 这在iOS模拟器中工作正常,甚至当我在我的iPhone上debugging应用程序。 但是,当我存档应用程序并使用TestFlight将其发送到我的手机时,它会崩溃。 我的崩溃日志充满了这个无限循环: 22 HDWR 0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad (HDWR.MainTabBarController)() -> () (MainTabBarController.swift:16) 23 HDWR 0x00262867 NRMA__voidParamHandler 24 HDWR 0x0014ea00 HDWR.HWTabBarController.viewDidLoad (HDWR.HWTabBarController)() -> () (HWTabBarController.swift:24) 25 HDWR 0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad […]

iOS:在故事板中将UIView的子类更改为UIScrollView

我创build了一个基于故事板的项目。 在视图控制器的视图中,需要放置一些额外的元素,这会导致视图高度的增加,使视图现在必须是可滚动的。 有没有可能简单地改变UIView类的UIScrollView在故事板? 它真的将顶级UIView转换为UIScrollView? 只是寻找一个快速简单的方法做这个没有太多的改变。 谢谢

UILabel子类用自定义颜色初始化

我的目标是在我的视图控制器中设置我的自定义UILabel子类的textColor 。 我有一个名为CircleLabel的UILabel子类。 这里是它的基础: class CircleLabel: UILabel { required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! } override init(frame: CGRect) { super.init(frame: frame) } override func drawRect(rect: CGRect) { self.layer.cornerRadius = self.bounds.width/2 self.clipsToBounds = true super.drawRect(rect) } override func drawTextInRect(rect: CGRect) { self.textColor = UIColor.whiteColor() super.drawTextInRect(rect) } func setProperties(borderWidth: Float, borderColor: UIColor) { self.layer.borderWidth = CGFloat(borderWidth) […]

采用UIKeyInput协议从蓝牙键盘获取input

我有一个蓝牙脚踏开关,基本上是一个无线键盘。 一个踏板发送上箭头键,另一个发送下箭头键。 我希望能够在按下其中一个踏板时在我的iPad应用程序中执行自己的代码。 踏板的制造者告诉我,我应该创build一个UITextField ,并在包含UIView中采用UIKeyInput协议,并使用beginningOfDocument和endOfDocument方法来执行我的代码。 我这样做了,但不pipe我做什么,都没有调用UIKeyInput或UITextInput方法。 任何人都可以通过这个来引导我,或者直接给我一个类似于这个的教程? 有没有更简单的方法来做到这一点? 谢谢你的帮助。 这是我的.h: #import <UIKit/UIKit.h> @interface Pedal_ProtocolViewController : UIViewController <UIKeyInput, UITextInput>{ UITextField *myTextField; } @property (nonatomic, retain) IBOutlet UITextField *myTextField; @end 这是我的.m: #import "Pedal_ProtocolViewController.h" @implementation Pedal_ProtocolViewController @synthesize myTextField; – (void)dealloc { [super dealloc]; } – (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super […]

inheritanceNSMutableDictionary

我想实现一个NSMutableDictionary的子类返回nil而不是在字典中不存在的关键字时抛出一个NSUndefinedKeyException。 但是,当我尝试添加对象到我的字典,我得到 [NSMutableDictionary setObject:forKey:]: method only defined for abstract class NilDictionary.h @interface NilDictionary : NSMutableDictionary { } @end NilDctionary.m @implementation NilDictionary – (id)valueForUndefinedKey:(NSString *)key { return nil; } @end 我真的不得不在我的子类中再次实现NSMutableDictionary的所有方法,还是有一些其他的类我应该inheritance? 澄清 :我最初的问题归咎于我无法正确阅读文档。 如果你需要子类NSMutableDictionary检查出正确的答案。 如果你想要一个当你的键不存在的时候返回nil的字典,NSMutableDictionary已经做到了。

如何inheritanceUITextField并覆盖drawPlaceholderInRect以更改占位符颜色

我有一个占位符文本设置3 UITextField 。 在其中一个UITextField我希望占位符文本是红色的。 现在谷歌search后,似乎做到这一点的最好办法是drawPlaceholderInRect UITextField并覆盖drawPlaceholderInRect 。 我如何去做子类化和重写drawPlaceholderInRect ? 我还没有find任何代码示例或教程,我是新来的Objective-C和iOS开发,所以find了棘手的工作。 回答: 创build了一个名为CustomUITextFieldPlaceholder的新的Objective-c类,它将子类UITextField 。 在CustomUITextFieldPlaceholder.minput下面的代码 @implementation CustomUITextFieldPlaceholder – (void)drawPlaceholderInRect:(CGRect)rect { // Set colour and font size of placeholder text [[UIColor redColor] setFill]; [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:12]]; } @end 在你的项目中实现上述内容 #import "CustomUITextFieldPlaceholder.h" 和 IBOutlet CustomUITextFieldPlaceHolder *txtName; 注意:这个工作,我相信是正确的做法,但我没有完全testing它。 希望这个例子能帮助别人。 编辑: 变 [[UIColor redColor] setFill]; 对于 [[UIColor colorWithRed:255.0 […]

iOS使用Swift行为parsingPFObject子类

我有一个奇怪的问题,我的子类在除了一个之外的所有视图控制器中工作。 我已经input了所有需要的东西,但是这一堂课给我的是 “在调用参数”className“中缺less参数” 我的子类 import Foundation import Parse class Session : PFObject, PFSubclassing { class func parseClassName() -> String { return "Session" } } //我已经删除了非重要的信息 我执行 Session.registerSubclass() 在应用程序的代表 在每一个类我有我可以通过创build一个会话 var se = Session() 但在这一堂课,这是行不通的。 class上 import UIKit import Parse class PurchaseViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var se = Session() // gives me […]

如何在UIButton子类中设置UIButtontypes

我是UIButton的子类,我想要的是将buttontypes设置为Round Rect。 Button.h @interface Button : UIButton {} – (void)initialize; @end Button.m @implementation Button – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initialize]; } return self; } -(id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self){ [self initialize]; } return self; } – (void)initialize { self.titleLabel.font = [UIFont systemFontOfSize:20]; self.titleLabel.textColor = [UIColor redColor]; […]