Tag: Objective C

UITextField自动完成

是否可以根据输入的内容自动完成UITextField? 我需要这个的原因是因为我有一组用户需要选择的预定义单词,而且列表大约是1000项。 我想在UITableView中显示并让用户选择但是在表格列表中有1k项目我认为不是一个好主意。 谢谢

更改所选UITableViewCell子类中的元素

我为我的应用程序实现了一个自定义UITableViewCell,并创建了一个自定义背景视图和selectedbackgroundview,两者都很好用。 但是,我在单元格上有几个其他图像和uilabels,我想要更改它的颜色。 我已经覆盖了以下方法,并且在选择单元格时它会正确记录,但它不会更改图像或文本颜色。 – (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if (selected) { NSLog(@”setSelected:YES”); separatorImage.image = [UIImage imageNamed:@”SeparatorSelected”]; titleLabel.textColor = [UIColor whiteColor]; } else { NSLog(@”setSelected:NO”); separatorImage.image = [UIImage imageNamed:@”Separator”]; titleLabel.textColor = [UIColor grayColor]; } } 任何想法我做错了什么? 更新 separatorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”Separator”]]]; [separatorImage setFrame:CGRectMake(99, 4, 5, 71)]; separatorImage.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:separatorImage]; […]

Objective C – 选择随机NIB文件?

您好我想让我的应用程序选择一个可供选择的randome XIB文件,并排除其中的3个。 HowToPlay *LetsPlay = [[HowToPlay alloc] initWithNibName:@”HowToPlay” bundle:nil]; LetsPlay.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:LetsPlay animated:YES]; [LetsPlay release]; 所以我知道如何通过上面的方法从一个nib文件加载,但我希望它能够选择一个随机的,然后排除某些。 我想要排除的:MainViewController,FlipSideViewController,HowToPlay 我想要的是:问题1,问题2,等等…… 我怎么能这样做的想法? 谢谢!。 祝你有美好的一天

CMAccelerometerData类比。 不推荐使用UIAccelerometer类

根据此文档, CMAccelerometerData类 (在Core Motion框架中找到)具有CMAcceleration类型的属性,称为acceleration ,它是包含3个值(double x,double y,double z)的struct的typedef 我是Objective-C的新手(我只知道C ++ ..)所以我的问题是:我如何访问,假设在我的代码中的某个时刻保留在该属性中的双y值? 我是否首先创建一个CMAccelerometerData类的实例,如下所示: CMAccelerometerData *myAccelerometer; 然后访问其加速属性: double axisYvalue = [myAccelerometer acceleration]; 以上显然是错的,不是吗? 我必须特别在加速中找到Y,所以我该怎么做? double axisYvalue = [myAccelerometer acceleration->y]; // no this is wrong as well.. 那怎么办呢? 最后一个问题,如果我可以:) 鉴于我提到的这个特定的类和属性..并且假设我已经实例化了我的CMAccelerometer类..现在每次,在我的代码中,我使用类似的东西 return [myAccelerometer acceleration->y]; // let’s say that’s the correct version 🙂 在一些 – (双)方法..我将在正在进行调用的特定时刻获得Y轴的值? 我问这个是因为我在阅读现在已弃用的UIAccelerometer类时感到困惑,你必须定义间隔并经常更新x,y,z的值等等。现在我可以获得正在运行的值在Y轴上调用加速属性的那一刻,是不是这样? phew …抱歉这段文字的长度! 🙂

当app force退出或崩溃时如何执行注销function

我想在app强制退出或意外崩溃时执行注销function。 要执行此任务,我需要调用Web服务从服务器端数据库中删除我的信息。但是当app强制退出或崩溃时,我无法调用Web服务。 所以请帮我解决这个问题。 applicationWillTerminate 和 applicationWillResignActive 委托方法对我不起作用! 谢谢!

addObjectsFromArray:不复制到全局NSMutableArray

以下是相关代码的部分示例。 static NSMutableArray *radioInputArray; static NSMutableArray *buttonsArray; – (IBAction)lookForRadioButtons:(id)sender { // NSLog(@”Testing”); NSError *error; NSString *radiostr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”getRadios” ofType:@”txt”] encoding:NSASCIIStringEncoding error: &error] ; if (radiostr == nil) { NSLog (@”Error! %@”, error); } else { NSLog(@”%@”,radiostr); NSString *radiotxt= [webView stringByEvaluatingJavaScriptFromString:radiostr]; NSLog(@”%@”, radiotxt); NSArray *myRadios = [radiotxt componentsSeparatedByString:@”::”]; [radioInputArray addObjectsFromArray:myRadios]; NSLog(@”%d”, myRadios.count); NSLog(@”Number […]

用AVFoundation崩溃video捕获

我正在尝试使用AVFoundation在我的应用程序中实现video捕获。 我在viewDidLoad下面有以下代码: session = [[AVCaptureSession alloc] init]; movieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; videoInputDevice = [[AVCaptureDeviceInput alloc] init]; AVCaptureDevice *videoDevice = [self frontFacingCameraIfAvailable]; if (videoDevice) { NSError *error; videoInputDevice = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; if (!error) { if ([session canAddInput:videoInputDevice]) [session addInput:videoInputDevice]; else NSLog (@”Couldn’t add input.”); } } AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; NSError *audioError = […]

我在哪里为iOS应用程序创建全局变量?

这是我的代码: 我希望能够创建一个全局的NSMutableArray,它可以存储Budget *对象,然后可以将其写入.pList文件……我只是在学习pLists,我对如何实现它们有点模糊。 .. 我在哪里错了? – (IBAction)btnCreateBudget:(id)sender { Budget *budget = [[Budget alloc] init]; budget.name = self.txtFldBudgetName.text; budget.amount = [self.txtFldBudgetAmount.text intValue]; // Write the data to the pList NSMutableArray *anArray = [[NSMutableArray alloc] init]; // I want this to be a global variable for the entire app. Where do I put this? [anArray addObject:budget]; [anArray […]

分组表视图 – 节间距

在分组表视图中,我可以控制两个部分之间的间距吗?

检索并更改touchUpInside更改为touchUpOutside的点

我已经使UISlider工作就像“滑动解锁”滑块一样。 我需要做的是确定将手指抬起的点被分类为touchUpOUTSIDE而不是touchUpINSIDE 。 这是您将手指滑过滑块末端太远的位置。 我猜这与UIButton相同,你可以按下按钮,然后将手指从按钮上移开,根据你走多远,它仍然可以被归类为touchUpInside 。 如果可能的话,我想用圆圈标记目标区域。 一旦我设法找到这一点,是否有可能改变它? 所以我可以拥有更大的目标区域? 我真的不知道从哪里开始。 谢谢