小编hal*_*y4b的帖子

instantiateViewControllerWithIdentifier并传递数据

Storyboard在我的应用程序中使用,我想将数据从一个视图传递到另一个视图.

而不是使用我正在使用的segues instantiateViewControllerWithIdentifier.在这种情况下,我实例化从我的第一个TableViewControllerNavigationController第二个TableViewController附加,因为我需要在第二个导航TableViewController.现在我想从我的第一个数据传递数据TableviewController,取决于点击哪一行,到第二行TableviewController.在这种情况下newTopViewController将是我,NavigationController但我现在的问题是如何将数据传递firstTableViewControllersecondTableviewController.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *identifier = [NSString stringWithFormat:@"%@Top", [menuArray objectAtIndex:indexPath.row]];


        UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];




    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

storyboard ios segue

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

使用AFNetworking 2.0下载PDF文件

我想更新到最新版本的AFNetworking.我想知道如何从服务器下载PDF以在我的应用程序中显示它.

在旧版本上我使用了这段代码:

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFHTTPResponseSerializer serializer]; 
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        [webView loadData:responseObject MIMEType:@"application/pdf" textEncodingName:nil baseURL:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handling
}

[operation start];
Run Code Online (Sandbox Code Playgroud)

在AFNetworking 2.0中完成相同工作的代码是什么样的?我是否必须使用另一类AFNetworking?

pdf afnetworking afnetworking-2

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

NSURLRequest缓存策略

我正在使用带有CachePolicy的NSURLRequest来下载NSData中的plist.当我更改我的plist的内容时,我的应用程序忽略了这一点,仍然显示缓存的内容.缓存持续多长时间?如果有,是否可以选择缓存数据持续多长时间?有没有办法检查NSURLRequest,如果服务器上的数据比缓存加载来自服务器的数据更新,或者它是否等于缓存使用缓存?

caching nsurlrequest ios ios5

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

AFHTTPRequestOperation取消请求

有没有办法取消AFHTTPRequestOperation?我用它来下载PLIST例如.所以我打算用一个按钮来取消下载或任务.有办法吗?

更新:

operationQueue = [NSOperationQueue new];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFPropertyListResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id propertyList) {

    NSLog(@"DONE");        

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"%@", error);

}
 ];

 [operationQueue addOperation:operation];
Run Code Online (Sandbox Code Playgroud)

所以我把"操作"放到"operationQueue"并且可以用以下命令停止操作:

[operationQueue cancelAllOperations];
Run Code Online (Sandbox Code Playgroud)

这只是队列中的一个操作.如果有多个,有没有办法明确停止操作?我想在控制台中出现以下错误 - 如果队列被取消,这是正常的吗?

错误域= NSURLErrorDomain代码= -999"无法完成操作.

ios afnetworking-2

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

保存由UIWebView本地显示的PDF

我有一个UIViewControllerUIWebView它显示根据该行已在之前点击PDF文件UITableView.现在我想为用户添加一个按钮,以便在本地保存此pdf文件以供离线使用.然后有一秒钟UITableView应该显示已保存的pdf的名称,然后点击它会UIViewController出现另一个,并在UIWebView离线状态下显示保存的pdf .什么是一个好的开始方式?谢谢

pdf iphone objective-c uiwebview ios

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

标签栏项目标题出现在故事​​板之前

我的应用程序以标签栏控制器开始,它有5个标签.在开始时,第一个显示其名称,但其他四个没有名称,直到我点击它们.然后根据用户使用的语言显示名称.如何在标签栏出现之前设置选项卡的名称?我正在使用故事板.有没有办法在编程栏中以编程方式设置标题,而所有其余的都是用故事板完成的?我在AppDelegate中试过类似[FirstViewController setTitle:NSLocalizedString(@"Titel1", nil)]; 但是我得到一个错误,即选择器setTitle没有类方法.谢谢.

iphone storyboard uitabbarcontroller

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

在从服务器加载 tableview 的 Plist 之前检查互联网

我将 Storyboard 与导航控制器和 prepareforsegue 一起使用。我有两个 UITableViews。如果您单击第一个表格中的一行,您将进入第二个表格。第二个表根据您在第一个表中单击的行从 plist 中选取其数据。只要有互联网连接,这就可以正常工作。如果没有互联网连接,它会崩溃。

现在我想在加载第二个表之前检查是否有互联网连接。如果没有互联网连接,我想显示一个 UIAlertView。

我想用 NSURLConnection 做到这一点,但我不知道在哪里实现代码。我会将它放在 prepareforsegue 的第一张桌子的 .m 中,还是放在第二张桌子的 .m 中?

谢谢。

iphone nsurlconnection nsurlrequest

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

MBProgressHUD UIWebView

MBProgressHUD遇到了一点问题.我有一个webview,想要在加载数据时显示HUD.HUD出现但只停留几秒钟并且已经消失但是webview没有完成加载.

-(void)viewDidAppear:(BOOL)animated{

// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];

// Add HUD to screen
[self.view.window addSubview:HUD];

// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;

HUD.labelText = @"Loading";
HUD.detailsLabelText = @"updating data";

// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(loadingWebView) onTarget:self withObject:nil animated:YES];} …
Run Code Online (Sandbox Code Playgroud)

iphone uiwebview mbprogresshud

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

UICollectionview类似于TableView的节数

在Tableviews中,我使用它来计算应该创建多少个部分:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
      return [[[MyArray objectAtIndex:section]objectForKey:@"Rows"]count];   
}
Run Code Online (Sandbox Code Playgroud)

现在我试图在Collection视图中实现相同的功能,但这里的代码是不同的:

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

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

我怎样才能像在Tableviews中那样实现相同的功能,因为在这种情况下我似乎无法使用objectAtIndex?

objective-c uitableview ios uicollectionview

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