Tag: Objective C

UITutViewCells与UIButton重叠时滚动

我需要创build一个表视图与一些button作为其元素,视图获取加载罚款,但同时向下滚动button重叠。 我认为旧的button不清除,新的button放在它上面。 请帮我解决这个问题。 提前致谢。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath { NSLog(@"index path %ld",(long)indexPath.row); static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; } UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:[NSString stringWithFormat:@"data %ld",(long)indexPath.row] forState:UIControlStateNormal]; button.frame = CGRectMake(0, 0, 160.0, 25); [cell.contentView addSubview:button]; return […]

uilabel尾截断

我工作的iOS应用程序使用目标C和我有一个uilabel的问题,我可以使用一些帮助。 基本上我有一个标签,可以改变大小,以适应文本,它会显示,但它有一个最大的高度,它可能是。 标签本身始终具有固定的宽度。 我已经打开UILineBreakModeWordWrap和UILineBreakModeTailTruncation使文本适合和截断,但是这会导致文本截尾太早,只剩下1个单词放置。 而不是把它移到下一行时,仍然有空间,它只是截断它。 self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, fixedWidth, 0); self.lineBreakMode = UILineBreakModeWordWrap | UILineBreakModeTailTruncation; self.numberOfLines = 0; [self sizeToFit]; 有没有find当uilabel实际上截断文本,所以我可以检查标签的高度,并添加到它,如果还有空间? 当有空间的时候,我总是试图在高度上加一个额外的行,这样可以避免早期的截断,但是随着整个标签的大小不一致, 任何想法都将非常感谢

如何caching或预加载SKLabelNode字体?

我正在做一个Sprite Kit应用程序,在我的场景中,我添加了一个SKLabelNode。 当我加载SKScene时,我注意到了一个相当大的滞后尖峰。 在分析应用程序后,我发现它来自创build一个带有纸莎草字体的SKLabelNode(尽pipe字体无关紧要)。 当我删除标签时,场景几乎立即启动,但标签需要额外的1-3秒。 我很确定这是从加载字体,因为当我回到主菜单,再次玩游戏,它立即再次启动。 现在有一种方法可以提前预加载字体,所以当玩家select这个级别的时候没有很大的停顿。

用不同的针脚颜色映射视图注释

我有一个超过200个对象的数组,我试图执行每个循环。 每个对象将有一个是/否的字段,我想显示一个不同的颜色标记依赖是/否的值。 从我所看到的是我的循环正在经历每个对象,然后在每个对象的末尾添加所有的注释。 由于我在循环中通过数组中的yes no值执行了一个检查,当所有的注释被添加到我的地图中时,它将使用来自数组中最后一个对象的yes / no值。 我怎么能这样做,这样标记将是不同的取决于每个元素的是/否值? 我的代码是 for (i = 0; i < [appDelegate.itemArray count]; i++) { item_details *tempObj = [appDelegate.itemArray objectAtIndex:i]; location.latitude = [tempObj.lat floatValue]; location.longitude = [tempObj.lon floatValue]; current_yesno = tempObj.yesno; MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc]initWithTitle:tempObj.name andCoordinate:location]; [self.mapView addAnnotation:newAnnotation]; [newAnnotation release]; } 我的注释代码如下 – (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ […]

NSString到NSArray

我想分裂成一个NSArray的NSString 。 例如,给出: NSString *myString=@"ABCDEF"; 我想要一个NSArray像: NSArray *myArray={A,B,C,D,E,F}; 如何用Objective-C和Cocoa做到这一点?

如何强制一个HKQuery加载最新的步骤计数?

目前我正在尝试使用HKStatisticsQuery来获取特定时间间隔内的步数。 我正在通过自己shaking手机进行testing。 但是,我得到的结果似乎不是最近的结果,除非: 我打开Health.app ,保持它在后台运行,然后在我的应用程序中再次testing; 我打开UP app ,让它在后台运行,并在我的应用程序中再次做testing。 如果我强制退出Health.app或UP app ,我的应用程序将无法再获取最新的数据。 因此,UP必须做我缺less的东西,但我找不到任何“重新加载”像HKHealthStore方法,或HKQuery/HKStatisticsQuery任何相关选项。 我使用的代码非常简单,如下所示。 我想知道是否有任何权限或我错过了什么。 let predicate = HKQuery.predicateForSamplesWithStartDate(date_start, endDate: NSDate(), options: HKQueryOptions.StrictStartDate) var type = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning) var query = HKStatisticsQuery(quantityType: type, quantitySamplePredicate: predicate, options: .CumulativeSum | .SeparateBySource, completionHandler: { query, stats, error in ( /*logs here*/ ) }) let healthStore = HKHealthStore() healthStore.executeQuery(query) 编辑:我也试图写一些数据到HealthKit但查询不会得到更新。 编辑2:当我说“最近的步骤计数”我的意思是这样的:1.执行HKQuery; […]

iOS:将两个NSMutableArray存储在.plist文件中

我想要在AppDelegate中存储两个我用作全局数组的NSMutableArray。 这两个数组也存储与NSUserDefaults。 现在我想知道我该如何创build这个文件,我怎样才能存储这两个数组,每次我修改它们。 你可以帮我吗?

AVAudioPlayer立即停止播放ARC

我试图通过AVAudioPlayer播放MP3,我认为这很简单。 不幸的是,这不是工作。 这是我所做的一切: 为了testing,我在Xcode中创build了一个新的iOS应用程序(Single View)。 我将AVFoundation框架添加到项目中,并将#import <AVFoundation/AVFoundation.h>到ViewController.m 我添加了一个MP3文件到应用程序的文档文件夹。 我改变了ViewControllers viewDidLoad:如下: 码: – (void)viewDidLoad { [super viewDidLoad]; NSString* recorderFilePath = [NSString stringWithFormat:@"%@/MySound.mp3", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]]; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:recorderFilePath] error:nil]; audioPlayer.numberOfLoops = 1; [audioPlayer play]; //[NSThread sleepForTimeInterval:20]; } 不幸的是,audio开始播放后显然停止。 如果我取消注释sleepForTimeInterval它播放20秒,然后停止。 只有使用ARC进行编译时才会出现此问题,否则,该工作将完美无瑕。

为什么使用UINavigationController时无法强制横向?

我发现很多问题强制UIViewController风景作为默认值: 如何强制UIViewController纵向在iOS 6中试试这个: – (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } – (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; } 但是当我在UINavigationController里面使用UIViewController的时候,我不能强迫使用landscape.Please help! *工作不好 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController]; [navControl setNavigationBarHidden:YES]; self.window.rootViewController = navControl; [self.window makeKeyAndVisible]; […]

使用CoreMotion框架在后台接收加速度计更新

我正在使用下面的代码来获取加速计数据(使用CoreMotion框架): CMMotionManager *motionManager = [[CMMotionManager alloc] init]; motionManager.accelerometerUpdateInterval = 1.0 / 60.0; [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { NSLog(@"ACCELEROMETER DATA = %@",accelerometerData); }]; 当应用程序处于前景模式时,我正在接收日志,但是当它进入后台时,只有当应用程序中的音乐正在播放时才会收到日志。 我已经将以下内容添加到应用程序信息plist文件中: – Required background modes – App registers for location updates – App plays audio or streams audio/video using AirPlay 问题是:当音乐不播放时,如何在后台接收加速度计更新?