小编klc*_*r89的帖子

如何从表格视图控制器的屏幕顶部显示UISearchBar

我想复制Facebook Messenger应用程序显示UISearchBar的方式.当你点击navigationBar中的leftBarButtonItem时,UISearchBar会从屏幕顶部向下显示/动画,当你取消时,它会从它的起源处向上消失.

我曾经把我的UISearchBar作为我的表格视图标题中的默认设置(在故事板中),但现在我想要做我上面所说的但我不知道从哪里开始.我的搜索显示器控制器仍在我的故事板中,但我已从故事板中的tableView控制器中删除了searchBar.

我感谢任何提供的帮助!

objective-c uinavigationcontroller uisearchbar ios ios7

5
推荐指数
1
解决办法
5030
查看次数

iOS 7 UIWebView 304缓存bug,空白页面

我在我的应用程序中发现了一个有UIWebView的问题.iOS 7缓存空白主体304响应,导致在用户刷新UIWebView时显示空白页面.这不是很好的用户体验,我试图弄清楚如何在iOS端解决这个问题,因为我无法控制Amazon S3如何响应标头(这是我用于资源托管的人).

这些人发现了这个错误的更多细节:http://tech.vg.no/2013/10/02/ios7-bug-shows-white-page-when-getting-304-not-modified-from-server /

我很感激任何帮助,我可以在应用程序方面而不是服务器方面解决这个问题.

谢谢.

更新:使用赏金的建议作为指导来修复此错误:

@property (nonatomic, strong) NSString *lastURL;

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    if ([self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"].length < 1)
    {
        NSLog(@"Reconstructing request...");
        NSString *uniqueURL = [NSString stringWithFormat:@"%@?t=%@", self.lastURL, [[NSProcessInfo processInfo] globallyUniqueString]];
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:uniqueURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0]];
    }
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    self.lastURL = [request.URL absoluteString];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiwebview ios ios7

5
推荐指数
1
解决办法
3507
查看次数

UITableView'hidden'部分每次刷新时都会导致更多的内存分配

我在Code Review上发布了这个,但被告知它可能会更好地作为Stack Overflow问题,因此这篇帖子.

我有一个UITableView,当用户点击该部分的标题时,我正在"隐藏"一个部分.我认为这是我提出的一个非常酷的实现,但事实证明,当隐藏此部分并且用户进行刷新时,每次刷新时(刷新完成后)大约1-2MB被添加到内存中.如果未隐藏UITableView的部分并且它们进行刷新,则不会分配额外的内存(正确的方式/行为).我知道1-2 MB并不多,但总而言之.我在Profiler中找不到任何泄漏,所以这就是我来到这里的原因.

我可能会忽略某些东西或者我的逻辑存在缺陷,并且会感谢所提供的任何帮助.对不起,下面是冗长的代码:

更新:已解决的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section)
    {
        case 0:
        {
            return [self friendRequests];
        }
        case 1:
        {
            return [self friends];
        }
        default:
        {
            if (self.showingBlockedUsers == YES)
            {
                return [self blockedUsers];
            }
            else
            {
                return 0;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

来自原始问题的旧代码:

- (void)refreshing:(UIRefreshControl *)refreshControl
{
    [refreshControl beginRefreshing];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://foobar.com/test.plist"]];
    request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
    request.timeoutInterval = 5.0;

    [NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:
     ^(NSURLResponse *response, NSData *data, …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios ios7

5
推荐指数
1
解决办法
253
查看次数

touches在CAShape中移动工程图图层慢/慢

正如在先前的StackOverflow问题中向我建议的那样,我正在尝试改进绘画方法,以使用户可以将线/点绘制到UIView中。我现在正在尝试使用CAShapeLayer而不是dispatch_async进行绘制。所有这些都可以正常工作,但是,在触摸移动时,连续拖入CAShapeLayer会变得很慢,并且路径会滞后,而我的旧代码(告诉我效率低下的代码)可以流畅,快速地运行。您可以在下面看到我的旧代码被注释掉。

有什么方法可以改善我想做的事情?也许我在想什么。

我将不胜感激。

码:

@property (nonatomic, assign) NSInteger center;
@property (nonatomic, strong) CAShapeLayer *drawLayer;
@property (nonatomic, strong) UIBezierPath *drawPath;
@property (nonatomic, strong) UIView *drawView;
@property (nonatomic, strong) UIImageView *drawingImageView;
CGPoint points[4];

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

    self.center = 0;
    points[0] = [touch locationInView:self.drawView];

    if (!self.drawLayer)
    {
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.lineWidth = 3.0;
        layer.lineCap = kCALineCapRound;
        layer.strokeColor = self.inkColor.CGColor;
        layer.fillColor = [[UIColor clearColor] CGColor];
        [self.drawView.layer addSublayer:layer];
        self.drawView.layer.masksToBounds = YES;
        self.drawLayer = layer;
    } …
Run Code Online (Sandbox Code Playgroud)

calayer uiview cashapelayer ios uibezierpath

5
推荐指数
1
解决办法
1775
查看次数

处理国际电话#和不正确的联系簿格式

我一直在推迟发布这个问题,因为我必须处理几个场景.基本上,我们的应用程序使用Twilio将带有验证码的短信发送到用户的手机,以确认他们实际拥有该设备.我们很高兴Twilio作为一个整体可以接受国际电话号码.然而,本地设备上有几个巨大的问题,目前我们认为我们现在应该只支持/保证美国的电话#s.但这就是我问这个问题的原因,看看你是否可以指出我更好的方向.

所以问题是以下情况:大多数用户在添加联系人时不输入+和国家/地区代码; 又称正确的格式,Twilio在请求正文中期望:+15555555555.我们的"解决方案"是从iOS联系簿中删除手机#s中的所有垃圾字符,例如()#+*-空格.然后我们在清理的前面添加+1 NSString,这使得手机#现在成为美国手机号码,这对其他国家/地区的其他用户来说是不正确的.我们的大多数用户都是美国公民,但这不是我们不能正确解决这个问题的借口.即使用户是"好用户"并使用+和国家/地区代码正确格式化他们的联系人,我们也必须忽略它,因为不幸的是,大多数用户的格式不正确.

我不相信获得设备的语言环境也是最佳解决方案.当然,必须有一种更简单,更好的方法来做到这一点,而不是对用户的位置做出任何假设?如果是的话,请你发一些建议吗?

编辑:我接受了奖励赏金的建议,这是我最终提出的:

NSDictionary *dictCodes = [NSDictionary dictionaryWithObjectsAndKeys:@"972", @"IL",
                                       @"93", @"AF", @"355", @"AL", @"213", @"DZ", @"1", @"AS",
                                       @"376", @"AD", @"244", @"AO", @"1", @"AI", @"1", @"AG",
                                       @"54", @"AR", @"374", @"AM", @"297", @"AW", @"61", @"AU",
                                       @"43", @"AT", @"994", @"AZ", @"1", @"BS", @"973", @"BH",
                                       @"880", @"BD", @"1", @"BB", @"375", @"BY", @"32", @"BE",
                                       @"501", @"BZ", @"229", @"BJ", @"1", @"BM", @"975", @"BT",
                                       @"387", @"BA", @"267", @"BW", @"55", @"BR", @"246", @"IO",
                                       @"359", @"BG", @"226", @"BF", @"257", @"BI", @"855", @"KH",
                                       @"237", …
Run Code Online (Sandbox Code Playgroud)

objective-c abaddressbook twilio ios

5
推荐指数
0
解决办法
1328
查看次数

有没有办法从Apple Watch访问心率传感器?

由于Apple正在将手表作为健康设备,因此开发人员可以获得心率吗?我没有看到心率传感器的文档.如果没有这些基本数据,我不确定他们如何计划第三方健康应用程序做得多.

objective-c ios watchkit

5
推荐指数
1
解决办法
1656
查看次数

HKObserverQuery 连续随机调用两次

我有一个正在尝试解决的问题,我已经设置了一个HKObserveryQuery,它运行良好并为我收集新数据。

然而问题是,有时当我返回“健康”应用程序并在手动将其添加到“健康”应用程序后删除一个项目时,我注意到我HKObserverQuery已经非常紧密地一起设置了两次火灾,我正在尝试这样做解决,因为我使用这个观察者稍后上传一些数据,并且我不想要重复的。

我将不胜感激提供的任何帮助。代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setup];

    return YES;
}

- (void)setup
{
    if ([HKHealthStore isHealthDataAvailable])
    {
        self.healthStore = [[HKHealthStore alloc]init];

        NSSet *readTypes = [NSSet setWithObject:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]];

        [self.healthStore requestAuthorizationToShareTypes:nil
                                                 readTypes:readTypes
                                                completion:^(BOOL success, NSError *error)
         {
             if (!error && success)
             {
                 [self observeHR];

                 [self.healthStore enableBackgroundDeliveryForType:
                 [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]
                 frequency:HKUpdateFrequencyImmediate withCompletion:^(BOOL success, NSError *error){}];
             }
         }];
    }
}

- (void)observeHR
{
    HKObserverQuery *query = [[HKObserverQuery alloc]initWithSampleType:[HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]
                        predicate:nil
    updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error)
    { …
Run Code Online (Sandbox Code Playgroud)

objective-c uiapplicationdelegate ios healthkit hkobserverquery

5
推荐指数
1
解决办法
1542
查看次数

子视图的子图层重叠更高的子视图

我有一个问题:我正在创建一个UIView从方法返回的,这部分很好,但我注意到的是,当我将子图层添加到其中一个子视图时,这些图层会重叠更高的子视图添加到的子图层的层次结构(textView和imageView)testViewCopy出现在这些子视图的顶部,并且它们不应该出现.我不知道这是怎么回事造成的.

码:

- (void)makeShareImages
{
    UIView *shareView = [self shareView];

    UIView *testViewCopy = [shareView viewWithTag:0];

    NSUInteger currentIndex = 1;

    for (NSDictionary *sub in self.array)
    {
        NSArray *lastArray = [sub objectForKey:@"LastArray"];

        for (NSDictionary *dict in lastArray)
        {
            @autoreleasepool
            {
                currentIndex ++;

                CircleLayer *layer = [[CircleLayer alloc]init];
                layer.portrait = [[dict objectForKey:@"Portrait"]boolValue];

                layer.frame = testViewCopy.bounds;

                [testViewCopy.layer addSublayer:layer];

                NSData *frameData = [self getSnapshotDataFromView:shareView];

                NSString *savePath = [NSString stringWithFormat:@"%@/%lu.png",somePath,(unsigned long)currentIndex];

                [frameData writeToFile:savePath options:0 error:nil];
            }
        }
    }
}

- (UIView *)shareView …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview ios

5
推荐指数
1
解决办法
2242
查看次数

PHPhotoLibrary获取专辑名称

我一直试图找到一种替代方法,用iOS 8中的Photos API获取专辑名称.使用ALAssets,我们可以使用:valueForProperty:ALAssetsGroupPropertyName但是使用Photos API,我似乎无法找到替代方案.有,这就是localizedTitlePHAssetCollection但这是不正确的或者,它只是给我的城市名称.我正在寻找能够返回群组实际名称的内容,包括与iTunes同步的内容.

感谢您在应用中如何做到这一点.Apple鼓励我们仅将照片API用于与8.0链接的应用,因此我不想同时使用ALAssetLibrary和Photos.

码:

- (NSString *)nameForAlbumInCollection:(id)collection
{
    NSString *title = nil;

    if ([PHAsset class])
    {
        title = [collection localizedTitle];
    }
    else
    {
        title = [collection valueForProperty:ALAssetsGroupPropertyName];
    }

    return title;
}

- (void)setup
{
    self.recentsCollectionDataSource = [[NSMutableOrderedSet alloc]init];
    self.favoritesCollectionDataSource = [[NSMutableOrderedSet alloc]init];
    self.albumsTableDataSource = [[NSMutableOrderedSet alloc]init];

    NSMutableArray *segmentTitles = [[NSMutableArray alloc]init];

    self.assetsFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];

    if (!self.parentController.canTakeOrChooseVideo)
    {
        fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %i",PHAssetMediaTypeImage];
    }

    for (PHAssetCollection *sub …
Run Code Online (Sandbox Code Playgroud)

objective-c ios alassetslibrary photosframework phphotolibrary

5
推荐指数
1
解决办法
6043
查看次数

AVCaptureOutput didOutputSampleBuffer停止调用

我有委托方法didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection的问题AVCaptureOutput.

当我将sampleBuffer添加到a时,它会在一两秒内停止调用CFArray.如果我删除CFArray代码,委托方法继续被调用,所以我不知道为什么CFArray代码导致它停止.我很感激任何帮助.

@property CFMutableArrayRef sampleBufferArray;

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    NSLog(@"Called");

    if (!self.sampleBufferArray)
    {
        self.sampleBufferArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
        CFArrayAppendValue(self.sampleBufferArray, sampleBuffer);
    }
    else
    {
        CFArrayAppendValue(self.sampleBufferArray, sampleBuffer);
    }
}
Run Code Online (Sandbox Code Playgroud)

控制台输出:

// Session start
2015-06-15 13:06:07.264 App[22467:5897858] Called
2015-06-15 13:06:07.286 App[22467:5897858] Called
2015-06-15 13:06:07.289 App[22467:5897858] Called
2015-06-15 13:06:07.315 App[22467:5897895] Called
2015-06-15 13:06:07.366 App[22467:5897895] Called
2015-06-15 13:06:07.384 App[22467:5897895] Called
2015-06-15 13:06:07.411 App[22467:5897895] Called
2015-06-15 13:06:07.449 App[22467:5897858] Called
2015-06-15 13:06:07.480 …
Run Code Online (Sandbox Code Playgroud)

objective-c avfoundation ios avcapturesession

5
推荐指数
1
解决办法
2062
查看次数

NSURLConnection didSendBodyData进展

我正在使用POST请求将一些数据上传到服务器,我正在尝试根据方法的totalBytesWritten属性更新UIProgressView的进度.使用下面的代码,我没有得到正确的进度视图更新,它总是0.000直到它完成.我不确定要乘以或除以什么来获得更好的上传进度.didSendBodyDataNSURLConnection

我很感激提供任何帮助!码:

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    NSNumber *progress = [NSNumber numberWithFloat:(totalBytesWritten / totalBytesExpectedToWrite)];

    NSLog(@"Proggy: %f",progress.floatValue);

    self.uploadProgressView.progress = progress.floatValue;
}
Run Code Online (Sandbox Code Playgroud)

objective-c nsurlconnection uiprogressview ios nsurlconnectiondelegate

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

在没有UIImagePickerController的情况下获取相机卷照片

我想知道如何在不打开UIImagePickerController的情况下从iPhone的相机胶卷/照片库中取出照片.我一直在尝试谷歌这个,但它总是指向我UIImagePickerController不愿意使用,因为它将打开另一个视图控制器.我知道这是可能的,因为Facebook Messenger具有此功能.它提供了我的相机照片选项,而无需打开iPhone的原生照片应用程序.作为参考,这是UIImagePickerController

的UIImagePickerController

这是Facebook Messenger App

Facebook Messenger

objective-c uiimagepickercontroller ios alassetslibrary

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

设置NSDocumentDirectory,使其不备份到iCloud

我正在尝试标记我的应用程序的NSDocumentDirectory的整个文件夹,以便它从iCloud备份中排除,但当我去终端并运行:xattr -plxv com.apple.MobileBackup我收到此错误:没有这样的xattr: com.apple.MobileBackup

提前感谢您提供的任何帮助.

这是我正在使用的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory];

    [self addSkipBackupAttributeToItemAtURL:pathURL];
}

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
        const char* filePath = [[URL path] fileSystemRepresentation];

        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;

        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    } else { // iOS >= 5.1

        NSLog(@"%d",[URL setResourceValue:[NSNumber …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios icloud

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