小编Guy*_*ood的帖子

正确发布NSTimer的方法?

在dealloc方法中发布NSTimer的正确方法是什么?它是用以下代码创建的?

-(void)mainTimerLoop {

     mainTimer = [NSTimer scheduledTimerWithTimeInterval:1/10
                                                  target:self 
                                                selector:@selector(gameLoop) 
                                                userInfo:nil
                                                 repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)

谢谢

iphone objective-c nstimer

4
推荐指数
1
解决办法
8018
查看次数

使用字符串变量打开NSURL - iPhone

我有一个名为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 …

iphone objective-c nsurl

4
推荐指数
1
解决办法
1万
查看次数

通过UIPopOver(iPad)更改UIImagePicker的大小

我正在尝试通过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

4
推荐指数
1
解决办法
5287
查看次数

从URL目标C显示图像

有没有办法实现以下避免使用"initWithData"?(万一你好奇,initWithData让我的应用程序被Apple标记为使用非法的API 叹息).

NSData * imageData = [NSData dataWithContentsOfURL : [NSURL URLWithString : [details image]]];
    picture = [[UIImage alloc] initWithData:imageData];
Run Code Online (Sandbox Code Playgroud)

非常感谢,

马丁

iphone url objective-c ios4

3
推荐指数
2
解决办法
7730
查看次数

"应用程序尝试以模态方式呈现活动控制器"iOS5中的错误

我有一个错误导致我的应用程序仅在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中?

iphone sdk xcode ipad ios5

3
推荐指数
1
解决办法
1万
查看次数

supportedInterfaceOrientations - 支持iOS6和iOS5

只是一个简单的问题.假设我已将我的应用更新到iOS6并更改了iOS5的shouldAutoRotate方法,如下所示:

- (BOOL) shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)

如果我仍然支持iOS5,我是否需要检查iOS版本,然后还要包含旧的iOS5方法(即shouldAutoRotateToInterfaceOrientation),如果应用程序是在运行iOS5的设备上运行的话?

谢谢 !

iphone rotation ipad ios5 ios6

3
推荐指数
1
解决办法
1722
查看次数

一起使用CGContextFillPath和CGContextStrokePath?iOS版

我正在使用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)

graphics objective-c cgcontext quartz-2d ios

3
推荐指数
1
解决办法
1387
查看次数

将Core Data/SQLite数据库下载到应用程序中?

理论上是否可以将Core Data数据库直接下载到应用程序中然后访问该数据库?

如果是这样的格式化考虑因素 - 任何SQLite数据库都可以工作还是需要特定的结构?

sqlite core-data objective-c ios

3
推荐指数
1
解决办法
584
查看次数

UISearchDisplayController/UISearchResultsTableView为每个搜索添加额外的行?IOS 7

我有一个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)

objective-c uisearchbar uisearchdisplaycontroller ios ios7

2
推荐指数
1
解决办法
1426
查看次数

NSURLSessionDownloadTask代表未触发

我正在玩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)

cocoa-touch objective-c nsurlconnection ios7 nsurlsession

2
推荐指数
2
解决办法
4339
查看次数