小编use*_*991的帖子

如何使用AFNetwork的AFHTTPRequestOperationManager设置HTTP请求主体?

我正在使用AFHTTPRequestOperationManager(2.0 AFNetworking库)来发送REST POST请求.但是经理只有调用来设置参数.

-((AFHTTPRequestOperation *)POST:(NSString *)URLString
                  parameters:(NSDictionary *)parameters
                     success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
                     failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
Run Code Online (Sandbox Code Playgroud)

我还需要用字符串设置HTTP请求体.我怎么能用AFHTTPRequestOperationManager来做呢?谢谢.

iphone objective-c ipad ios afnetworking

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

无法更改UITableView蓝色高亮颜色

我设置:

cell.selectionStyle = UITableViewCellSelectionStyleGray;
Run Code Online (Sandbox Code Playgroud)

并使用代码突出显示一行:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone
Run Code Online (Sandbox Code Playgroud)

即使我设置为灰色,高光颜色始终为蓝色.如果我设置:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

它工作正常,没有突出显示.但是不能合作:

cell.selectionStyle = UITableViewCellSelectionStyleGray;
Run Code Online (Sandbox Code Playgroud)

它只显示蓝色而不是灰色.任何的想法?谢谢.

objective-c ios

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

ARC不允许将非Objective-C指针类型void*隐式转换为NSString*__ strong*

迁移到ARC时出现上述错误.这是代码:

static NSString *cashBalanceKeyPath = @"test";

...

[xxx forKeyPath:cashBalanceKeyPath options:NSKeyValueObservingOptionNew context:&cashBalanceKeyPath];

...

-(void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {

    if (&cashBalanceKeyPath == context)   < error here
    {
      ...
    }
Run Code Online (Sandbox Code Playgroud)

当我用桥时:

if (&cashBalanceKeyPath == (__bridge NSString *)context)
Run Code Online (Sandbox Code Playgroud)

我收到了错误: Comparison of distinct pointer types (NSString *__strong* and NSString *)

我怎样才能进行转换?提前致谢.

cocoa objective-c ios automatic-ref-counting

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

NSMutableArray中的addObject是复制还是保留?

当您将对象添加到集合中(例如)时NSMutableArray,对象是否被复制(即值语义)或被保留(即引用语义)?

我对示例感到困惑:

NSMutableString *testStr = [@"test" mutableCopy];
NSMutableArray *arrayA = [[NSMutableArray alloc] init];

[arrayA addObject:testStr];
NSLog(@"%@", arrayA);    // output: test

testStr = [@"world" mutableCopy];
NSLog(@"%@", arrayA);    // output: test

// testStr is copied - value semantics

NSMutableArray *testArr = [@[@1, @2] mutableCopy];
NSMutableArray *arrarB = [[NSMutableArray alloc] init];

[arrarB addObject:testArr];
NSLog(@"%@", arrarB);      // output: [1, 2]

[testArr addObject:@3];
NSLog(@"%@", arrarB);      // output: [1, 2, 3]

// testArr is retained - reference semantics
Run Code Online (Sandbox Code Playgroud)

您可以看到:如果对象是NSMutableString,则看起来对象已被复制-您更改对象将不会影响数组中的对象。

但是,如果对象是NSMutableArray,则在更改对象时,数组中的对象也会更改-就像保留对象或通过引用传递一样。 …

objective-c nsmutablearray ios

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

如何在Objective-C中初始化对象

我不确定如何初始化Objective-C类中的各种属性.请假设我在你的答案中是Objective-C的新用户......

我有以下课程:

考试班

@interface Test : NSObject
@property (nonatomic, strong) NSString *name;
@end
Run Code Online (Sandbox Code Playgroud)

TestManager类

@interface TestManager : NSObject
@property (nonatomic, strong) NSMutableArray *tests; // array of Test objects (array size unknown until runtime)
@end
Run Code Online (Sandbox Code Playgroud)

控制器类

@interface TestController : NSObject
@property (nonatomic, strong) TestManager *aManager;
-(void)initManager;
-(void)doSomething;
@end
Run Code Online (Sandbox Code Playgroud)

我想要一个像initManager被调用的方法:

-(void)initManager
{
    // how can I init the aManager which will have an array of Test objects
}
Run Code Online (Sandbox Code Playgroud)

它将自动分配一个对象数组,以存储在manager类中,这样我就可以执行以下操作:

-(void)doSomething
{
   NSString *name = ((Test *)[self.aManager.tests objectAtIndex:0]).name;
}
Run Code Online (Sandbox Code Playgroud)

我甚至不确定initManager是否是正确的使用方法 - …

memory-management allocation objective-c

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