Tag: 属性

@synthesize与使用自我

我是iOS新手,从教程和教授那里学习。 在.h文件中我们有: @interface ViewController : UIViewController <UITextFieldDelegate> @property (strong, nonatomic) IBOutlet UILabel *myResponse; @property (strong, nonatomic) IBOutlet UITextField *myInput; @end 在.m文件中我们有: @sysnthesize myResponse @synthesize myInput 我的问题是这样的:在.m文件中,添加@synthesize ,然后使用像[myInput <do something here>]与消除@synthesize并使用[self.myInput <do something here>] 。 我在Xcode 5上运行,所以我明白,我有自动综合可用,但两者之间有一个更微妙的差异? 我的教授使用了@synthesize而我之前使用的教程只是使用self.propertyName ,因此我很好奇。 谢谢。

是否有可能获得与MPMediaItemvideo相关的元信息?

我正在做一些MPMediaItems的工作,特别是我试图得到用户设备上的video列表。 现在,来自iTunes的video将被locking,因此无法从第三方应用播放,但用户添加的video(如家庭电影)可以播放,即使是来自iTunes的用户也可以查看并显示其元信息。 但是,这里是我越来越绊倒:我似乎无法find这些文件的任何video特定元信息? MPMediaItem类的引用有一个很长的属性列表,你可以访问,但他们大多是audio特定的。 像MPMediaItemPropertyAlbumTitle或MPMediaItemPropertyComposer 。 甚至还有一个专门针对Podcast的属性,但似乎找不到像“Season Number”或“Episode Number”或“Show Title”之类的内容。 这些信息显然是由iTunes存储的,而且是由内部的video应用程序显示的,但我找不到任何方法来获取它自己。 这些是我可以在类参考中find的唯一字段: NSString *const MPMediaItemPropertyPersistentID ; // filterable NSString *const MPMediaItemPropertyAlbumPersistentID ; // filterable NSString *const MPMediaItemPropertyArtistPersistentID ; // filterable NSString *const MPMediaItemPropertyAlbumArtistPersistentID ; // filterable NSString *const MPMediaItemPropertyGenrePersistentID ; // filterable NSString *const MPMediaItemPropertyComposerPersistentID ; // filterable NSString *const MPMediaItemPropertyPodcastPersistentID ; // filterable NSString […]

如何引用一个类的方法

我正在编写一个App.net客户端,并使用ADNKit作为与ADN服务器通信的框架。 我从Zephyr的一个开源代码中得到了一些想法,这个app.net客户端已经变成了一个开源项目。 他们用于显示post列表(PostStreamViewController)的视图控制器使用一个数据控制对象和一个名为apiCallMaker的属性的configuration对象。 该属性是这样定义的: typedef void (^APIPostListCallback)(NSArray *posts, PostListMetadata *meta, NSError *error); … @property (nonatomic, copy) void (^apiCallMaker)(APIPostParameters *parameters, APIPostListCallback callback); 这允许他们为主时间线重用相同的数据控制器对象,提及时间线等。他们所需要做的就是为每个这样的后置streamtypes提供一个configuration文件,每个types引用不同的api调用。 例如,在提及poststream的configuration文件中,他们像这样定义self.apiCallMaker: – (void (^)(APIPostParameters *parameters, APIPostListCallback callback))apiCallMaker { return [^(APIPostParameters *parameters, APIPostListCallback callback) { [APIUserMentionStream getUserMentionStreamWithParameters:parameters userID:self.userID completionHandler:callback]; } copy]; } 这是变长了,但坚持我。 我觉得这个方法非常酷,它使得数据控制器对象更轻,configuration文件更简单轻便。 在我的实现中,我反而像这样声明我的apiCallMaker : // this is the default parameters returned by […]

IOS:CS193p fall2013任务2:添加一个button让用户重新启动游戏

我正在学习课程CS193P(IOS开发)在iTunes上,我刚刚开始assignment2。 我被困在要求我重新开始游戏的任务上。 在项目上的一点点背景:我正在为我的CardGameViewController中的重新启动button新添加的操作方法的代码。 我有两个私人的属性: 游戏和甲板 。 我使用CardGameViewController中的延迟初始化来初始化它们,当用户第一次触摸一个button时(翻转卡片)(教授在课堂上讲过的原始项目只是UI上的一些卡片,用户可以翻转它们并匹配它们,没有重新启动function,这是我要求在作业中添加的。)为了让用户重新启动游戏,我想我需要重新初始化上面提到的两个属性并更新UI。 我尝试了下面的代码,但是当我触摸我刚刚添加的button时程序崩溃了: – (IBAction)touchRestartButton:(UIButton *)sender { self.game = nil; self.theDeck = nil; // Maybe I also need to initialize the two properties again here using some code which I cannot figure out right now…. [self updateUI]; } 任何人都可以向我解释如何在objective-c中重新初始化一个属性吗?(我也试过[self.game release],但编译器阻止我这样做,因为它说它是在ARC模式下)还是有其他方法完成这个重新开始的游戏任务?

适当的实例化UISearchDisplayController

我做了一些search,答案仍然不清楚。 我正试图在TableViewController(TVC)内创build一个UISearchDisplayController的实例。 在我的TVC的标题中,我宣布了一个searchDisplayController属性: @interface SDCSecondTableViewController : UITableViewController @property (nonatomic, strong) NSArray *productList; @property (nonatomic, strong) NSMutableArray *filteredProductList; @property (nonatomic, strong) UISearchDisplayController *searchDisplayController; @end 这样做会产生错误: 属性'searchDisplayController'尝试使用超类“UIViewController”中声明的实例variables“_searchDisplayController” 在实现文件中添加@synthesize searchDisplayController摆脱了错误。 任何人都可以帮我理解这个错误吗? 我使用的是Xcode 4.6.2,但是我觉得属性是自动从Xcode 4.4开始合成的。

为什么使用属性?

所以我已经在Objective-C编程了一年多了,我似乎无法理解对属性的使用。 我已经search了几次互联网,但从来没有真正find一个很好的解释。 我明白如何创build它们: @property (something, something) something *variableName; @syntheize variableName; 但是,我应该做所有我的实例variables属性。 对我来说,从我所知道的来看,这似乎是对代码的浪费。 但是当我在网上查看代码时,有时候我会在一个类中看到25个属性。 我认为这是浪费。 我唯一使用它们的时间是从一个UITableView单元格传递信息到一个详细的viewController 。 为此,我使用: @property (copy) NSString *myString; 你还可以解释一下: nonatomic , copy , retain , assign等的意思。 谢谢

重要的改变位置委托方法不被调用

我所有的代码都在AppDelegate.m中: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; _locationMgr = [[CLLocationManager alloc] init]; [_locationMgr setDelegate:self]; if([_locationMgr respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) [_locationMgr setAllowsBackgroundLocationUpdates:YES]; CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus]; if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) { NSLog(@"relaunching because of significant location change – restarting SLC"); [_locationMgr startMonitoringSignificantLocationChanges]; } else { if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) { NSLog(@"launching with authorization to […]

Objective-c中的自定义属性属性

像VB.NET一样,可以在Objective-C中创build自定义属性属性? 例如,在VB.NET中,您可以创build“Browsable”属性并在运行时读取它,以确定是否显示属性。 Public Class Employee <Browsable(True)> _ Public Property Property1() As String Get End Get Set(ByVal Value As String) End Set End Property <Browsable(False)> _ Public Property Property2() As String Get End Get Set(ByVal Value As String) End Set End Property End Class 我想在Objective-C中做同样的事,即使它是一个固定的属性,只能在编译时设置,根本不能修改。 我想要做的是添加一个属性到我的类的属性,以确定属性是否应该序列化。 我知道标准的Objective-C属性(只读,非primefaces等),但这些不能帮助我…除非你有创造性的方式来使用它们。 我还研究了使用C属性和__attribute__(("Insert attribute here"))关键字,但是C具有特定的属性来满足特定的目的,我甚至不确定你可以在运行时读取它们。 如果我错过了一个可以帮助我的人,请告诉我。 我试过使用typdef 。 例如: typdef int […]

Swift:计算属性的默认初始值设定项

看来我不能使用可用于存储属性的默认初始值设定项方法给计算属性一个默认值。 这里有一个用例,我需要这个: @IBDesignable public class MyRoundedCornersView: UIView { @IBInspectable var cornerRadius: CGFloat { get { return self.layer.cornerRadius } set { self.layer.cornerRadius = newValue } } } 我想给cornerRadius一个默认值。 但以下不起作用(只是增加= 8.0 ): @IBDesignable public class MyRoundedCornersView: UIView { @IBInspectable var cornerRadius: CGFloat = 8.0 { get { return self.layer.cornerRadius } set { self.layer.cornerRadius = newValue } } […]

从AppDelegate.swift为一个视图控制器分配一个值

我尝试从AppDelegate.swift分配一个值到一个视图控制器没有成功。 我的控制器名为DestinationsViewController ,它在Main.storyboard中的id是destinationsID 。 DestinationsControllerembedded在导航控制器中。 我想改变的对象被命名为“标签”。 这是代码: if let destinationsViewController = storyBoard.instantiateViewControllerWithIdentifier("destinationsID") as? DestinationsViewController { if let label = destinationsViewController.label{ label.text = "Super!" } else{ println("Not good 2") } } else { println("Not good 1") } 不幸的是,我收到这样的消息:“不好2”。 不是很好 :-( 谢谢。 import UIKit class DestinationsViewController: UIViewController { @IBOutlet weak var label: UILabel! override func viewDidLoad() { […]