小编Dav*_*vid的帖子

Swift 4表达式类型'@value CGRect'在没有更多上下文的情况下是模糊的

我正在尝试为矩形实现动画以执行模态垂直滑动.但是,当我尝试编译代码时,我得到以下错误"Swift 4表达式类型'@value CGRect'是模糊的,没有更多上下文".我已将问题隔离到传递给CGRect init值的参数,但根据Apple的iOS文档,这些参数应该足以指定我需要设置动画的"帧"视图.

这是我的代码:

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    guard
        let fromView = transitionContext.viewController(forKey: .from),
        let toView = transitionContext.viewController(forKey: .to)

    else {
            return
    }
    let containerView = transitionContext.containerView
    containerView.insertSubview((toView.view)!, belowSubview: (fromView.view)!)

    let toFrame = transitionContext.finalFrame(for: toView)

    let screenBounds = UIScreen.main.bounds

    let bottomLeftCorner = CGPoint(x: 0, y: screenBounds.height)

    let finalFrameForVC = CGRect(origin: bottomLeftCorner, size: screenBounds.size)

    UIView.animate(withDuration: 2, delay: 1,
                   options: [], (using: transitionContext.finalFrame(for: fromView)),
        animations: {
            fromView.view.frame = finalFrameForVC
    },
        completion: { _ in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    })
}
Run Code Online (Sandbox Code Playgroud)

cgrect swift

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

如何在UITableView中获取所有单元格

假设我有一个有多行的UITableView.我希望在某个时间点将所有UITableViewCells作为NSArray.我试过了

[tableView visibleCells] 
Run Code Online (Sandbox Code Playgroud)

但是这种方法存在问题:我不能拥有当前屏幕中当前不存在的所有单元格.所以我转向另一种方法:

-(NSArray *)cellsForTableView:(UITableView *)tableView
{
    NSInteger sections = tableView.numberOfSections;
    NSMutableArray *cells = [[NSMutableArray alloc]  init];
    for (int section = 0; section < sections; section++) {
        NSInteger rows =  [tableView numberOfRowsInSection:section];
        for (int row = 0; row < rows; row++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];   // **here, for those cells not in current screen, cell is nil**
            [cells addObject:cell];
        }
    }
    return cells;
}
Run Code Online (Sandbox Code Playgroud)

但似乎这种方法仍然无法获得那些未在屏幕上显示的细胞.谁可以帮我这个事?

uitableview ios

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

如何在MapView上绘制MKPolyline?

我有一个要在地图上绘制的点数组,它已经被解码了:

- (void) drawRoute:(NSArray *) path {
    NSInteger numberOfSteps = path.count;

    CLLocationCoordinate2D coordinates[numberOfSteps];
    for (NSInteger index = 0; index < numberOfSteps; index++) {
         CLLocation *location = [path objectAtIndex:index];
         CLLocationCoordinate2D coordinate = location.coordinate;

         coordinates[index] = coordinate;
    }

    MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
    [map addOverlay:polyLine];
}
Run Code Online (Sandbox Code Playgroud)

其中"map"是MKMapView的一个实例,并且路径表示已经解码的点集.

我认为用这条线[map addOverlay:polyLine];就可以了.我在某些页面中看到过这种方法:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
    polylineView.strokeColor = [UIColor redColor];
    polylineView.lineWidth = 1.0;

    return polylineView;
}
Run Code Online (Sandbox Code Playgroud)

polylineView在地图上实际绘制的是什么?我也尝试将MKPolyline(从上面的方法)传递给最后一个方法的"<MKOverlay> overlay"参数,但抛出异常.

我想我很亲密,但我现在不知道该怎么做.

请帮忙!非常感谢你提前.

iphone mkmapview ios

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

如何捕获反序列化异常?

当unserialize生成错误时,如何在PHP上捕获异常?

php serialization try-catch

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

iOS - 设置为0时仍然存在UICollectionView间距 - 如何设置单元格之间没有间距

我有一个简单的UICollectionView,我在InterfaceBuilder中设置了0间距但是当我用单元格填充集合视图时,仍然有一些间距.是否有一些特殊而且不是很明显我需要做的是为了实际看到一个带有0间距的集合视图单元格而不是设置为0间距?谢谢.

编辑*一些代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor clearColor];

    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(2, 2, cell.frame.size.width -4, cell.frame.size.height -4)];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.font = [UIFont boldSystemFontOfSize:20];
    lbl.text = [NSString stringWithFormat:@"$%0.0f", [[amountsArray objectAtIndex:indexPath.row] floatValue]];
    lbl.textAlignment = NSTextAlignmentCenter;
    lbl.layer.borderWidth = 1;

    [cell addSubview:lbl];
    [lbl release];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

iphone layout spacing ios uicollectionview

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

重置CoreData持久性存储

基本上,我要做的是擦除CoreData持久存储中的所有数据,然后导入新数据.你会怎么做?似乎最简单的解决方案是调用[NSPersistentStoreCoordinator removePersistentStore:error:]然后删除文件.这是最好的做法吗?它是线程安全的吗?

非常感谢你,

#

问题0.1:是

我正在尝试更新CoreData持久性存储中的数据.我的用户正在查看包含统计数据的表格视图.我想通过删除所有现有数据,然后导入新数据来更新应用程序.我想显示一个进度视图,告诉用户应用程序没有挂起.

resetPersistentStore在AppDelegate中添加了以下方法(persistentStoreCoordinator供参考):

// ...
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
// ...

/**
 Returns the persistent store coordinator for the application.
 If the coordinator doesn't already exist, it is created and the application's store added to it.
 */
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] …
Run Code Online (Sandbox Code Playgroud)

iphone multithreading core-data

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

使用NSURLSession设置cookie

嗨,我正在开发一个Iphone应用程序我想在服务器响应后设置cookie并将其用于另一个请求.我的网络请求看起来像.

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
    NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
    NSLog(@"sttaus code %i", httpResp.statusCode);
    if (error) {
        [self.delegate signinWithError:error];
    }
    else {
        [self.delegate signinWithJson:data];
    }
}] resume];
Run Code Online (Sandbox Code Playgroud)

但我不知道如何设置cookie.我知道我必须使用,NSHTTPCookieStorage但我不知道如何设置.而且我也希望将cookie用于其他请求.有没有人知道这件事?需要帮忙.谢谢.

看到我试过这种方式

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{      
    if(error) {
        [self.delegate signinWithError:error];
    }
    else {
        NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
        NSHTTPCookie *cookie;

        NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];

        NSDictionary* headers = …
Run Code Online (Sandbox Code Playgroud)

session-cookies ios nsurlsession

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

带有换行符 (%0A) 的 iOS mailto 链接转换为 &lt;BR&gt;

下面的链接最近在邮件应用程序中打开时没有换行。

<a href="mailto:info@example.com?subject=Question&body=%0A%0A%0A----------%0AVersion: 2.0%0ABuild: 12345" id="address">support by email</a>
Run Code Online (Sandbox Code Playgroud)

相反,它在邮件应用程序中显示如下:

<BR><BR><BR>----------<BR>Version: 2.0<BR>Build: 12345
Run Code Online (Sandbox Code Playgroud)

但应该看起来像:

在此处输入图片说明

它适用于 iOS 13,但现在不再适用。我在另一个应用程序和类似的%0A. 使用的时候也会出现%0D%0A

空格被%20javascript编码。

有没有其他人看到过这个或有尝试的想法?

编辑:提交错误报告 FB9146675。请考虑这样做。只有当重点放在一个主题上时,它才会被看到。

email safari newline ios

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

swift NSTimer userinfo

我正在尝试使用NSTimer的userinfo传递UIButton.我已经阅读了NSTimers上有关stackoverflow的每篇文章.我变得非常接近,但却无法到达那里.这篇文章有所帮助

Swift NSTimer将userInfo检索为CGPoint

func timeToRun(ButonToEnable:UIButton) {
    var  tempButton = ButonToEnable
    timer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("setRotateToFalse"), userInfo: ["theButton" :tempButton], repeats: false)    
}
Run Code Online (Sandbox Code Playgroud)

计时器运行的功能

func setRotateToFalse() {
    println(  timer.userInfo )// just see whats happening

    rotate = false
    let userInfo = timer.userInfo as Dictionary<String, AnyObject>
    var tempbutton:UIButton = (userInfo["theButton"] as UIButton)
    tempbutton.enabled = true
    timer.invalidate()    
}
Run Code Online (Sandbox Code Playgroud)

nstimer userinfo swift

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

CURL HTTP2请求

我想知道是否有人成功设法使用CURL通过新的APNS API(HTTP2)发送推送通知.

APNs Provider API页面上给出的示例请求

这是请求必须如何:

HEADERS

\- END_STREAM

\+ END_HEADERS

:method = POST

:scheme = https

:path = /3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0

host = api.development.push.apple.com

apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b

apns-expiration = 0

apns-priority = 10

content-length = 33
Run Code Online (Sandbox Code Playgroud)

数据

\+ END_STREAM

{ "aps" : { "alert" : "Hello" } }
Run Code Online (Sandbox Code Playgroud)

但是使用以下命令我得到错误"curl:(16)HTTP/2流1没有干净地关闭:error_code = 8":

curl \

--verbose \

--http2 \

--cert <APPLICATION_CERT_FILE> \

--key <APPLICATION_KEY_FILE> \

--header "Content-Type: application/json" \

--header ":method: POST" \

--header ":path: /3/device/<DEVICE ID>" \

--data '{ "aps" …
Run Code Online (Sandbox Code Playgroud)

curl

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