小编vgr*_*vgr的帖子

将块保留在字典中

我有自己的方法,以块作为参数.我想跟踪NSDictionary中的那个块.将块添加到字典的最佳方法是什么?

我尝试了这段代码但是在执行下面的行(setObject ...)后,字典仍然是空的.我认为这是因为该块不是NSObject类型.但是这样做的正确方法是什么?

- (void)startSomething:(NSURLRequest*)request block:(void (^)(NSURLResponse*, NSData*, NSError*))handler {

    NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];

    [pendingRequests setObject:handler forKey:connection];
}
Run Code Online (Sandbox Code Playgroud)

编辑:

没关系.我不知道我在想什么.3分:

  1. 块是objc对象
  2. 错字:setObject应该是setValue
  3. forKey是一个字符串,因此它应该是[连接描述]或类似的东西

无论如何我现在解决了我的问题:

- (void)startSomething:(NSURLRequest*)request block:(void (^)(NSURLResponse*, NSData*, NSError*))handler {

    NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
    [pendingRequests setValue:handler forKey:[connection description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {

        void (^handler)(NSURLResponse*, NSData*, NSError*);
        handler = [pendingRequests valueForKey:[connection description]];
        handler(nil, nil, nil);
    });
}
Run Code Online (Sandbox Code Playgroud)

nsdictionary grand-central-dispatch ios objective-c-blocks

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

区分黑白iPhone?

我们可以使用uname来区分iphone 3GS与iphone 4 vs ipod touch vs ipad之间的区别......

但是我们怎样才能分辨出白色和黑色iphone之间的区别呢?

我想基于此自定义用户体验.

谢谢.

iphone ios4

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

UIButton在UIScrollView后面

我在UIScrollView后面有一个UIButton.滚动的背景是透明的,按钮位于右下角.所以它是可见的.

问题是当UIButton低于滚动时,它不会响应任何触摸事件.在这种情况下,它需要什么来响应触摸事件?

谢谢

iphone cocoa-touch uibutton uiscrollview ios

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

在UITableViewCell里面的MKMapView

我有一个UITableView与UITableViewCells,其中包含MKMapView.

问题:如果表单元格被选中,然后移动地图,您会看到mapview全部为白色,您只看到"Legal"标签.

有谁之前经历过这个吗?

截图

这是整个代码:

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.table.backgroundColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    MKMapView *map = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 220, 70)];

    MKCoordinateSpan span = …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uitableview mkmapview

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