我正在从一个非常慢的服务器上下载JSON数据.从服务器获得一个resoonse大约需要一分钟.我使用AFNetworking库,我的代码抛出"请求超时"错误:
NSString *urlString = [NSString stringWithFormat:@"%@/account.do?JSON&sysparm_action=getRecords",baseUrlString];
NSString *login = [[NSUserDefaults standardUserDefaults] objectForKey:@"login"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:login password:password];
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
[self parseJsonWithAccountsData:responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", operation.responseString);
[self performSelectorOnMainThread:@selector(failedWithContactsDownload) withObject:nil waitUntilDone:YES];
}];
Run Code Online (Sandbox Code Playgroud)
没有找到设置超时的方法AFHTTPRequestOperationManager.我该怎么做?
我有UILabel两个由新行分隔的属性字符串.第一个字符串的字体大小设置为17,第二个字符串设置为14. NSMutableAttributedString如果内容不能放在一行中,我希望我的第一个字符串调整为最小字体大小.
那可能吗?
UILabel通过在IB中为纯文本设置"自动缩小到最小字体大小" 来配置此类行为非常简单,但不知道如何为属性文本执行此操作.
这是我的代码:
NSString *eventName = @"Looong Event Name";
NSString *placeString = @"My place";
eventName = [eventName stringByAppendingString:@"\n"];
NSMutableAttributedString *attrName = [[NSMutableAttributedString alloc] initWithString:eventName];
[attrName addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0, [eventName length])];
NSMutableAttributedString *attrPlace = [[NSMutableAttributedString alloc] initWithString:placeString];
[attrPlace addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, placeString.length)];
[attrPlace addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, placeString.length)];
NSMutableAttributedString *finalString = [[NSMutableAttributedString alloc] initWithAttributedString:attrName];
[finalString appendAttributedString:attrPlace];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.attributedText = finalString;
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Objective-C文件中使用Swift类.我"moduleName-Swift.h"在我的SuperViewController.m文件中包含了文件,但是当我尝试SuperViewController.h使用Swift-classas方法参数声明一个公共方法时,我显然得到一个错误:"Expected a type"
swift-class如果我只能包含projectModule-Swift.h在.m文件中,我如何在头文件中使用?
我有一个字符串"First line | second line | third line"
如何|用 new line字符替换?
我正在尝试使用,preg_replace但没有说谎
我知道这个问题在SO上被多次询问过,但我没有设法让它在我的项目中发挥作用......
所以,我想使用子类NSOperation并使其下载文件NSURLConnection.做正确的方法是什么?这是我的代码不起作用:首先,我在循环中添加所有操作:
DownloadFileOperation *operation;
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
for (int i=0; i<10; i++) {
operation = [[DownloadFileOperation alloc] init];
operation.urlString = pdfUrlString;
[queue addOperation:operation];
operation = nil; }
Run Code Online (Sandbox Code Playgroud)
这是我的子类:
@interface DownloadHandbookOperation : NSOperation <NSURLConnectionDelegate>
{
}
@property (strong, nonatomic) NSString *urlString;
@end
@implementation DownloadHandbookOperation
{
NSString *filePath;
NSFileHandle *file;
NSURLConnection * connection;
}
- (void)start
{
if (![NSThread isMainThread])
{
[self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
return;
}
NSURL *url = [[NSURL alloc] initWithString:[self.urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; …Run Code Online (Sandbox Code Playgroud) 我有UITableViewController与UIScrollView内UIView作为它的头.
UIScrollView用于显示图像的幻灯片:
UITableView
-UITableViewHeaderView
-UIView
-UIScrollView
-UIImageView
...
-UIPageControl
Run Code Online (Sandbox Code Playgroud)
每个图像都有一个带有标题和描述的子视图:
UIImageView
-UIView
-UILabel
-UILabel
Run Code Online (Sandbox Code Playgroud)
当我需要更新我的tableView一个委托方法被调用,它重新加载a tableView和调用addImages方法中的数据:
- (void)eventsUpdated
{
if ([self respondsToSelector:@selector(setRefreshControl:)])
[self.refreshControl endRefreshing];
[self.tableView reloadData];
[self addImages];
}
Run Code Online (Sandbox Code Playgroud)
以下是我添加图片的方式:
- (void)addImages
[self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *subview = [self createImageViewForEvent:[images objectAtIndex:i] inFrame:frame];
subview.frame = frame;
[self.scrollView …Run Code Online (Sandbox Code Playgroud) 我在application.properties文件中指定了Spring属性.如何从环境变量中填充这些属性?
这是我尝试过的,但它似乎不起作用:
application.properties
spring.datasource.url=jdbc:postgresql://#{ systemProperties['DATABASE_HOST']}:5432/dbname
spring.datasource.username = postgres
spring.datasource.password = postgres
Run Code Online (Sandbox Code Playgroud) 我添加了两个滑动手势识别器(向左滑动和向右滑动)到我的UITableView.之后,我的表视图已停止滚动.同时-(void)didSelectRowAtIndex工作正常.可能是什么问题?
我所做的就是将对象库中的Swipe Gesture Recognizer拖放到我的UITableView上.
如果我删除它们,我的表开始再次滚动.
UPD:
升级到Xcode 4.5后会发生这种情况.在旧版本的Xcode中没有这样的问题.为了避免这种行为 - 以UIGestureRecognizers编程方式添加,而不是在IB中添加.
我正在尝试利用@Value注释并从属性文件中自动填充我的字符串变量,但没有运气.值未设置且未设置null.
这是我的配置:
SendMessageController.java
@RestController
public class SendMessageController {
@Value("${client.keystore.type}")
private static String keystoreType;
@RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
public ResponseEntity<SendMessageResponse> sendMessage(@Validated @RequestBody SendMessageRequest messageRequest) {
.......
}
Run Code Online (Sandbox Code Playgroud)
application.properties
client.keystore.type=JKS
Run Code Online (Sandbox Code Playgroud)
休息-servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="org.example.controllers" />
<context:property-placeholder location="classpath:application.properties"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<mvc:annotation-driven />
</beans>
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序并尝试访问keystoreType变量时,它始终是null.我究竟做错了什么?
我正在使用Spring Boot和EhCache开发日历应用程序。我正在尝试缓存以下方法:
@Override
@Cacheable(value = "concerts")
public List<Event> getEvents(String eventsForUser, Date startDate, Date endDate) throws Exception {
return fetchEventsFromTheServer(eventsForUser, startDate, endDate);
}
Run Code Online (Sandbox Code Playgroud)
挑战是我想操纵返回的缓存结果。例如,检查是否存在给定日期但另一个用户的缓存,然后取而代之(只要两个用户都符合特定条件)。
因此,在返回结果之前,我想:
我认为最好的办法是创建一个自定义缓存管理器,该缓存管理器将对缓存的Concert执行所有操作,并对所有其他方法使用默认的自动配置的缓存,但是我无法让我的自定义管理器正常工作并且没有发现任何好处如何实现自定义CacheManager的示例。
这是我所拥有的:
Application.java:
@SpringBootApplication
@ComponentScan
@EnableCaching
@EnableScheduling
public class SpringBootWebApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<SpringBootWebApplication> applicationClass = SpringBootWebApplication.class;
@Bean(name = "eventsCacheManager")
public EventsCacheManager eventsCacheManager() {
return new EventsCacheManager();
}
@Primary
@Bean(name = "cacheManager") …Run Code Online (Sandbox Code Playgroud) cocoa-touch ×6
ios ×4
xcode ×4
iphone ×3
java ×3
objective-c ×3
spring ×2
spring-boot ×2
afnetworking ×1
ehcache ×1
nsoperation ×1
php ×1
spring-cache ×1
string ×1
swift ×1
uiview ×1