背景
我正在开发一个简单的iPad应用程序,允许用户同时浏览具有不同登录的同一网站.因此我有两个UIWebView,他们应该有不同的cookie存储,所以用户可以在第一个帐户登录UIWebView,另一个帐户登录UIWebView.
我试过了什么?
我认为解决方案是在UIWebView我拥有的两个中实现不同的cookie存储.
Sasmito Adibowo写了一篇文章实现自己的Cookie存储,它提供了有关如何WebView在Mac上使用自定义cookie存储的详细信息.
这是通过修改WebView要发送的NSURLRequest,向其添加cookie标头,并WebView从响应头拦截响应并从中提取cookie并将其保存到我们自己的cookie存储中来完成的.
从技术上讲,它是通过实现这两个委托方法来完成的:
- (void)webView:(WebView *)sender resource:(id)identifier didReceiveResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)dataSource
- (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource
Run Code Online (Sandbox Code Playgroud)
虽然它没有记录,UIWebView但确实支持上述方法之一,方法名称略有不同:
- (NSURLRequest *)uiWebView:(UIWebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(id)dataSource
Run Code Online (Sandbox Code Playgroud)
但是,UIWebView没有等效的委托方法webView:resource:didReceiveResponse:fromDataSource:,因此我无法从响应标头中提取cookie.
问题
有没有办法必须UIWebView使用自定义cookie存储,所以这两个UIWebView可以拥有自己的cookie存储?
谢谢!
可能重复:
在UISearchBar中设置取消按钮的样式
我正在尝试为搜索UISearchBarBackground栏设置图像,我可以使用搜索栏的子视图为搜索栏设置图像,但我无法为搜索栏的取消按钮设置图像.我获得UINavigationButton了按钮的搜索栏子视图,但我不知道如何设置图像UINavigationButton.谁能帮我?
先感谢您
我必须归档一个float有价值的东西INFINITY,然后去归档它.
这是我的示例代码:
要归档的对象:
@interface CodeInf : NSObject <NSCoding>
@end
@implementation CodeInf
- (void)encodeWithCoder:(NSCoder *)encoder {
float inf = INFINITY;
[encoder encodeFloat: inf forKey:@"INFINITY"];
}
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
float decodedInf = [decoder decodeFloatForKey: @"INFINITY"];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
以下是归档/解密代码:
CodeInf *myCodeInf = [[CodeInf alloc] init];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myCodeInf];
myCodeInf = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Run Code Online (Sandbox Code Playgroud)
归档工作,但是归档会引发错误:
*由于未捕获的异常'NSRangeException'终止应用程序,原因:'* - [NSKeyedUnarchiver decodeFloatForKey:]:键(INFINITY)的值(inf)太大而不适合32位浮点数'
这是dearchiver中的一个错误,还是我做错了什么?
我正在尝试将DropBox集成到我的iPhone应用程序中.但我得到的错误就像
[ERROR] DropboxSDK: unable to link; app isn't registered for correct URL scheme (db-xpt9oxj57x9ftci)
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?
我有一个文本(一本书的故事).我正在拿UILabel来展示它.但它没有让我看到.我使用以下代码:
CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];;
[commentsTextLabel setNumberOfLines:0];
commentsTextLabel.textColor = [UIColor blackColor];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
[commentsTextLabel setFont:[UIFont fontWithName:@"ACaslonPro-Regular"size:17]];
labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
commentsTextLabel.frame=CGRectMake(20, 200, 280, labelsize.height);
commentsTextLabel.text = story;// more than 1000 lines
[self.view addSubview:commentsTextLabel];
Run Code Online (Sandbox Code Playgroud)
当我调试我的代码时,我发现labelize.height出现在我的情况下13145.Still它没有显示.如果我减少15000到11000,那么文本最终会显示在....
labelsize = [story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280,15000)lineBreakMode:NSLineBreakByWordWrapping];
请帮帮我.谢谢
我实现了moveRowAtIndexPath来重新排列UITableView中单元格的顺序并设置UITableViewCellEditingStyleNone,这样它在编辑模式下只显示重新排序的控件.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常但是当进入编辑模式时,它仍然向右缩进每个单元格的内容,期望为删除或插入控件腾出空间.我没有使用它,所以它变成一个奇怪的空白空间.有没有办法在编辑模式下避免这种行为?
我试图使用系统字体使UILabel字体粗体和斜体,但我不能同时使用这两种样式.那么是否可以使用系统字体使字体粗体和斜体?这是我的代码,
lblTitle.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
Run Code Online (Sandbox Code Playgroud)
要么
lblTitle.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
Run Code Online (Sandbox Code Playgroud)
我想要我的字体Bold和Italic.谁能帮我?先感谢您.
我想以格式检索日期和时间,例如"2013年5月31日星期五中午12:00".如何使用NSDateFormatter实现这一目标?
如何在UITextView中增加行间距?
我希望使用默认系统字体,即大小为15的Helvetica.
我想从iphone发布/共享图像到服务器.图像已准备好分享.我使用以下代码使用大多数网站显示的方式
NSData *imageData = UIImageJPEGRepresentation(image, 100);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"0x0hHai1CanHazB0undar135";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding: NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"imageToAttach\"; filename=\"%@\"\r\n",fileName]dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
Run Code Online (Sandbox Code Playgroud)
但它给了我一些内部服务器错误,然后我指出服务器要求图像的流字节..如何将图像转换为流然后将该流发布到服务器?
ios ×9
objective-c ×8
iphone ×7
uilabel ×2
xcode ×2
app-id ×1
archiving ×1
cookies ×1
dropbox-api ×1
ios6 ×1
uibutton ×1
uidatepicker ×1
uifont ×1
uiimage ×1
uisearchbar ×1
uitableview ×1
uitextview ×1
uiwebview ×1
xcode4 ×1