在dealloc方法中发布NSTimer的正确方法是什么?它是用以下代码创建的?
-(void)mainTimerLoop {
mainTimer = [NSTimer scheduledTimerWithTimeInterval:1/10
target:self
selector:@selector(gameLoop)
userInfo:nil
repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个名为storedURL的变量,格式为www.xxxxx.com.我试图使用以下代码在用户单击按钮时在Safari中打开此URL.
-(IBAction)launchWeb {
NSString *url = [NSString stringWithFormat: @"%@",
storedURL];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Run Code Online (Sandbox Code Playgroud)
但是,单击按钮时应用程序崩溃.
有人可以帮助纠正我的代码吗?
编辑
mvds的代码崩溃如下:
2011-04-02 14:01:41.542伦敦[16791:207] + [NSURL urlWithString:]:无法识别的选择器发送到类0x103dcbc 2011-04-02 14:01:41.545伦敦[16791:207] *终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:'+ [NSURL urlWithString:]:无法识别的选择器发送到类0x103dcbc'*第一次调用堆栈:(0 CoreFoundation 0x00fd95a9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x0112d313 objc_exception_throw + 44 2 CoreFoundation 0x00fdb17b + [NSObject(NSObject)doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00f4a966 __ forwarding + 966 4 CoreFoundation 0x00f4a522 _CF_forwarding_prep_0 + 50 5 London 0x00006bce - [DetailViewController launchWeb] + 126 6 UIKit 0x0022b4fd - [UIApplication sendAction:to:from:forEvent:] + 119 7 …
我正在尝试通过UIPopOver更改UIImagePicker的大小.代码如下所示.问题是PopOver大小无法正常显示 - 它会以正确的大小短暂闪烁,然后动画缩小到通常的默认大小.
任何人都可以告诉我如何改变弹出窗口的大小?
- (void)showImagePickerForPhotoLibrary {
NSLog(@"Picker");
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(@"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
//popoverController.popoverContentSize = CGSizeMake(768, 1000);
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
}
}
else {
[app.mainViewController presentModalViewController:imagePickerController animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud) objective-c uiimagepickercontroller ipad uipopovercontroller
有没有办法实现以下避免使用"initWithData"?(万一你好奇,initWithData让我的应用程序被Apple标记为使用非法的API 叹息).
NSData * imageData = [NSData dataWithContentsOfURL : [NSURL URLWithString : [details image]]];
picture = [[UIImage alloc] initWithData:imageData];
Run Code Online (Sandbox Code Playgroud)
非常感谢,
马丁
我有一个错误导致我的应用程序仅在iPad上的iOS5下崩溃.
当用户点击uibarbutton项目中的项目时,将调用以下代码:
- (void)optionSelected:(NSString *)option {
[self.optionPickerPopover dismissPopoverAnimated:YES];
if ([option compare:@"Map View"] == NSOrderedSame) {
NSLog(@"Map View");
MapView * map = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:map];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self action:@selector(removeCurrent)];
map.navigationItem.rightBarButtonItem = rightButton;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[map release];
[rightButton release];
[split presentModalViewController:map animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议为什么会出现在iOS5中?
只是一个简单的问题.假设我已将我的应用更新到iOS6并更改了iOS5的shouldAutoRotate方法,如下所示:
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
如果我仍然支持iOS5,我是否需要检查iOS版本,然后还要包含旧的iOS5方法(即shouldAutoRotateToInterfaceOrientation),如果应用程序是在运行iOS5的设备上运行的话?
谢谢 !
我正在使用CGContextFillPath绘制Quartz 2D形状,如下所示:
CGContextRef conPattern = CGBitmapContextCreate(NULL,
shp.size.width*2,
shp.size.height*2,
8,
0,
rgbColorSpace,
(CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
CGContextSetLineWidth(conPattern, 10);
CGContextSetStrokeColorWithColor(conPattern, [UIColor blackColor].CGColor);
Line * start = [verticesPassed objectAtIndex:0];
StandPoint * startPoint = start.origin;
CGContextMoveToPoint(conPattern, ([startPoint.x floatValue]-shp.origin.x)*2 , ([startPoint.y floatValue]-shp.origin.y)*2);
for (Line * vertice in verticesPassed) {
StandPoint * standPoint = vertice.origin;
CGContextAddLineToPoint(conPattern, ([standPoint.x floatValue]-shp.origin.x)*2, ([standPoint.y floatValue]-shp.origin.y)*2);
}
CGContextSetFillColorWithColor(conPattern, [UIColor yellowColor].CGColor);
CGContextFillPath(conPattern);
[self drawText:conPattern startX:0 startY:20 withText:standName];
[self drawText:conPattern startX:0 startY:50 withText:standNumber];
//Make the main image and color it with pattern.
CGImageRef cgImage = CGBitmapContextCreateImage(conPattern);
UIImage …Run Code Online (Sandbox Code Playgroud) 理论上是否可以将Core Data数据库直接下载到应用程序中然后访问该数据库?
如果是这样的格式化考虑因素 - 任何SQLite数据库都可以工作还是需要特定的结构?
我有一个UISearchDisplayController,它在iOS7下表现得很奇怪.我第一次进行搜索时,一切正常,UISearchResultsTableView正确显示结果.
问题是我第二次进行搜索(在解除表格之后),空白行(看起来像一个单元格)被添加到搜索结果表的顶部:

然后,每个后续搜索都会在表格的顶部添加另一个空白行,依此类推,依此类推.
这是代码:
//Setup the search bar.
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 360.0f, 44.0f)];
UIBarButtonItem * searchBarButton = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
searchBar.delegate = self;
controller = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];
controller.searchResultsDataSource = self;
controller.searchResultsDelegate = self;
self.tabBarController.navigationItem.rightBarButtonItems = @[searchBarButton];
- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
if (isLoading) {
return;
}
[self filter : searchText];
[controller.searchResultsTableView reloadData];
}
- (void)filter : (NSString *)text {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(name CONTAINS[cd] %@ OR number CONTAINS[cd] %@)", text, text];
searchResults = [standArray filteredArrayUsingPredicate:predicate]; …Run Code Online (Sandbox Code Playgroud) 我正在玩NSURLSession的教程.我可以成功下载图像,但下载进度和下载完成的代表不会触发.这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString * imageUrl = @"http://ichef.bbci.co.uk/naturelibrary/images/ic/credit/640x395/r/ro/rock_pigeon/rock_pigeon_1.jpg";
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession * session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];
//Download image.
NSURLSessionDownloadTask * getImageTask = [session downloadTaskWithURL:[NSURL URLWithString:imageUrl]
completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Error sadly for you is %@", [error localizedDescription]);
}
UIImage * downloadedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:location]];
dispatch_async(dispatch_get_main_queue(), ^ {
self.imageView.image = downloadedImage;
});
}];
[getImageTask resume];
// Do any additional setup after loading the view, typically from …Run Code Online (Sandbox Code Playgroud)