小编Buy*_*ian的帖子

使用参数创建视图控制器

我想创建一个新的viewController并在实例化时传递数据。

我有一个包含一些数据的字典,并希望在viewController创建后立即访问该数据。

我已经试过了:

//create the recipe
    myRecipe = [[RecipeCard alloc] init];
        //create a dictionary here...

//call the setRecipeItems method of the recipe I have created
        [myRecipe setRecipeItems: dictionary]

;
Run Code Online (Sandbox Code Playgroud)

问题在于setRecipeItems在加载视图之前触发。

理想情况下,我想执行以下操作:

myRecipe = [[[RecipeCard alloc] initWithData:dictionary];

但这对我没有用

谢谢

objective-c

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

AFNetworking错误的URL

我在这里遇到一个奇怪的问题,并且我没有发现任何其他人有同样的问题.

我正在AFNetworking做一个AFJSONRequestOperation.

它在第一次建立网络时起作用.但是,一旦建立网络连接,相同的代码就会失败,并显示"错误的URL"错误.

奇怪的是,应用程序甚至在失败之前都没有ping服务器,我正在使用Charles来嗅探所有请求.

还有其他人经历过这个吗?

供参考,以下是代码:

  NSURL *url = [NSURL URLWithString:JOIN_URL];
     AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

   // httpClient.parameterEncoding = AFJSONParameterEncoding;
     NSString *path = [NSString stringWithFormat:@"%@?%@",JOIN_URL, getString];

     NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:path parameters:nil];


    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request

                                                                                      success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

                                                                                          NSLog(@"SUCCESS JSON: %@", JSON);

                NSLog(@"RESPONSE URL: %@",response.URL);
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"FAIL JSON: %@", JSON);
        NSLog(@"FAIL ERROR: %@", error.description);
        NSLog(@"RESPONSE URL: %@",response.URL);

        UIAlertView *alert …
Run Code Online (Sandbox Code Playgroud)

objective-c ios afnetworking

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

本地通知限制

我知道 Apple 将本地通知的数量限制为 64。在阅读 Apple 的文档后,SO 和博客上的一些帖子......我有点困惑。

是吗:

  1. 您只能为该应用程序安排 64 条通知。
  2. 您一次不能安排超过 64 个通知。(它们会在 fireDate 之后自动删除吗?

ios uilocalnotification swift

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

NSMutableArray问题

谁能解释为什么这段代码破坏了我的应用:

NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:@"recipeA", @"recipeA1", @"recipeA2", @"recipeA3",@"recipeA4",@"recipeA5",@"recipeA6",@"recipeA7",nil];

//these both break the app with invalid pointer type warnings
NSLog("What is 0: %@", [myArray objectAtIndex:0]);
NSLog("What is the count: %i", [myArray count]);
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c

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

xib文件没有SafeArea选项

我正在尝试为iPhoneX更新我的应用程序,但是没有“ SafeArea”指南。他们只是在情节提要中,而不是在个别笔尖中吗?

xcode ios autolayout iphone-x

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

Swift 4 子字符串崩溃

我对 Swift 4 字符串操作的最佳实践有点困惑。

您如何处理以下情况:

let str = "test"
let start = str.index(str.startIndex, offsetBy: 7)


Thread 1: Fatal error: cannot increment beyond endIndex
Run Code Online (Sandbox Code Playgroud)

想象一下,您不知道上面变量“str”的长度。由于“start”不是可选值,那么防止崩溃的最佳实践是什么?

swift

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

&变量

可能重复:
为什么在Cocoa编程中传递错误而不是错误?

我有一个问题,我似乎无法找到答案......

我正在使用SBJsonParser,我发现有一行代码令人费解:

NSError *error;
self.jsonData = [jsonParser objectWithString:responseString error:&error];
Run Code Online (Sandbox Code Playgroud)

错误参数前面的&是什么?(&错误)?

cocoa-touch objective-c

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