Tag: 目标C

预期的':'词法或预处理器错误

那么这应该是一个非常快速和容易的问题。 我正在创build一个滚动视图,我已经完成了所有的事情,但有一个错误,我只是不明白! 就像它只是混乱,没有任何意义的我! 错误://预期':' ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController{ } @property (weak, nonatomic) IBOutlet UIScrollView *ScrollView; @end ViewController.m @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; [self ScrollView setScrollEnabled YES] // Expected ':' [self ScrollView setContentSize: CGSizeMake(320, 900)] } 编辑:我做了所有这一切,它只是说预期的标识符。 [super viewDidLoad]; [self.ScrollView setScrollEnabled: YES]; [[self.ScrollView setContentSize: CGSizeMake(320, 900)]]; //expected […]

iOS – 删除我已删除的属性的引用

我之前创build了一个button,将其命名为“hi”。 我手动删除了我的.h和.m文件中的代码,并从故事板中删除了该button,现在我得到下面的错误: 2014-02-08 18:31:53.135 MadLibs2 [7645:70b] *由于未捕获的exception'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:该类不是键值编码兼容的键hi “。 如何删除“hi”引用? // JBViewController.h // MadLibs2 #import <UIKit/UIKit.h> @interface JBViewController : UIViewController // Properties manage an object's internal data //// A properties data is stored in an instance variable or ivar (eg, *sliderLabel) // The property accesses ivars via getter/setter methods (aka accessors) // put @property in front […]

如何在iPhone中以降序对数组进行sorting

我想按降序对数组进行sorting,我可以按升序对数组进行sorting,这里是我的代码按升序sorting, NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:NO]; NSArray * descriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; sortedArray = [array sortedArrayUsingDescriptors:descriptors]; dictionaryWithSortedYears = [[NSMutableDictionary alloc] init]; NSString *tempDateKey = nil; for (TreeXmlDetails *list in sortedArray) { id obj = [dictionaryWithSortedYears objectForKey:list.year]; if(!obj) { if(tempDateKey == nil) { arrayFromList = [[NSMutableArray alloc] init]; tempDateKey = list.year; } } […]

将NSDictionary数据放在ModelObject中

我收到一个JSON对象(转换为NSDictionary),我想把它放到我的模型对象。 我试过这个 { Description = "Desc."; EndTime = "2014-06-25T05:35:00"; Id = ""; IsActive = 1; StartTime = "2014-06-25T05:30:00"; Title = "Test appointment"; }, { Description = Qww; EndTime = "2014-06-26T02:58:00"; Id = ""; IsActive = 1; StartTime = "2014-06-26T01:58:00"; Title = q; } 我想将它存储到我的模型对象NSobject中。 但只能得到第一个dictioanry 我已经试过这一个 MyAppoinmentModel * modelObj; modelObj =[[MyAppoinmentModel alloc]init]; modelobj = [[MyAppoinmentModel […]

限制平移手势移动到90度

如果我为前者创build了一行 在图中显示为通过CAShapeLayer连接A和B,在该行的中心我有一个UIView ,其中包含了平移手势。 如何使UIView移动到某个方向创build90度,如图所示,红线表示UIView可以移动的方向? 中点应该从线的中心开始,沿着我已经更新的图中所示的方向。

UITableView不呈现

所以我有一个UITableView作为接口生成器中另一个视图的子视图,而不是渲染。 我已经检查过,section方法的返回数是1,并且section方法中的行数返回一个大于0的数。 这是我的代码 – – (void)viewDidLoad{ //[super viewDidLoad]; _trendingImageView.image = [UIImage imageNamed:@"trending.png"]; [self.scrollView setScrollEnabled:YES]; [self.scrollView setClipsToBounds:YES]; self.scrollView.delegate = self; UINib *nib = [UINib nibWithNibName:@"RecommendationCell" bundle:nil]; [self.recommendationsTableView registerNib:nib forCellReuseIdentifier: reco recommendationCellIdentifier]; self.recommendationsTableView.scrollEnabled = YES; } -(void)executeRecSearch{ @try{ [AJAXUtils getAsyncJsonWithUrl:(NSURL *)[NSURL URLWithString:[NSString stringWithFormat:someUrl]] callback:^(NSDictionary *returnjson){ if(returnjson != nil){ self.recommendations = returnjson[@"Node"][@"Recommendations"][@"Components"]; NSLog(@"COUNT: %d", [self.recommendations count]); [self performSelectorOnMainThread:@selector(renderRecommendations) […]

我在NSUserDefaults结构NSMutableArray错了吗? “尝试插入非属性列表对象”

我很简单地试图保存在NSUserDefaults的struct s的NSMutableArray / NSArray : typedef struct { int key; } provision; provision p1; p1.key = 4; NSValue *p1Value = [NSValue value:&p1 withObjCType:@encode(provision)]; provision p2; p2.key = 5; NSValue *p2Value = [NSValue value:&p2 withObjCType:@encode(provision)]; NSMutableArray *provisions = [[NSMutableArray alloc] init]; [provisions addObject:p1Value]; [provisions addObject:p2Value]; [[NSUserDefaults standardUserDefaults] setObject:provisions forKey:@"Provisions"]; 我按照这里的指南 ,把所有的结构存储为NSValue 。 但是最后一行会导致运行时错误: *由于未捕获的exception'NSInvalidArgumentException',原因:'* – [NSUserDefaults […]

如何委托工作和委托工作stream程在Objective-C

我是Objective-C的新手。 我正在学习Objective-C。 你会不会让我知道这个代码是如何工作的,以及你是否会帮助理解委托人在Objective-C中的工作stream程 SampleProtocol.h #import <Foundation/Foundation.h> @protocol SampleProtocolDelegate <NSObject> @required – (void) processCompleted; @end @interface SampleProtocol : NSObject { id <SampleProtocolDelegate> _delegate; } @property (nonatomic,strong) id delegate; -(void)startSampleProcess; @end 我在下面的代码中添加SampleProtocol.m后 #import "SampleProtocol.h" @implementation SampleProtocol -(void)startSampleProcess{ [NSTimer scheduledTimerWithTimeInterval:3.0 target:self.delegate selector:@selector(processCompleted) userInfo:nil repeats:NO]; } @end 为标签创build一个IBOutlet并将其命名为myLabel,并按照以下方式更新代码以在ViewController.h采用SampleProtocolDelegate #import <UIKit/UIKit.h> #import "SampleProtocol.h" @interface ViewController : UIViewController<SampleProtocolDelegate> { IBOutlet UILabel […]

如何比较两个给定的时间与当前时间?

我想比较当前时间和不同date的两个不同的时间。我的代码是 NSString *time1 = record.trigger_from_time; NSString *time2 = record.trigger_to_time; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *date1= [formatter dateFromString:time1]; NSDate *date2 = [formatter dateFromString:time2]; NSLog(@"%@,%@",date1,date2); 我得到日志为2000-01-01 09:12:00 + 0000,2000-01-01 12:30:00 +0000 但我目前的时间是2014-04-01 17:06:18。 我正在从当前date NSDate *now = [NSDate date]; NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; timeFormatter.dateFormat = @"HH:mm"; [timeFormatter setTimeZone:[NSTimeZone systemTimeZone]]; NSLog(@"The Current […]

NSDateFormatter这个格式

我想为这个date格式(例如)创build一个NSDateFormatter对象: 2016-04-15 15:00:00 我已经试过yyyy-mm-dd hh:mm:ss但是当我试图将它附加到这样的date时: date = [formatter dateFromString:dateString]; 它给了我nil 。 什么是正确的方法来做到这一点? 谢谢!