Permalink
Browse files

* Method to create an NSURLRequest from a TTURLRequest

* Method to load a request in a TTWebController
* Bug fixes in search bars
  • Loading branch information...
joehewitt committed Jun 10, 2009
1 parent b789448 commit b5e86f3c67315adac4c2160251ed5572ed0cba66
View
@@ -109,7 +109,6 @@ BOOL TTOSVersionIsAtLeast(float version) {
return NO;
}
-
NSLocale* TTCurrentLocale() {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
View
@@ -70,8 +70,9 @@ - (void)scrollToTop {
UIScrollView* scrollView = (UIScrollView*)[self firstParentOfClass:[UIScrollView class]];
if (scrollView) {
CGPoint offset = scrollView.contentOffset;
- if (offset.y != self.top) {
- [scrollView setContentOffset:CGPointMake(offset.x, self.top) animated:YES];
+ CGPoint myOffset = [self offsetFromView:scrollView];
+ if (offset.y != myOffset.y) {
+ [scrollView setContentOffset:CGPointMake(offset.x, myOffset.y) animated:YES];
}
}
}
View
@@ -63,10 +63,6 @@ - (void)textFieldDidEndEditing:(UITextField *)textField {
if ([_delegate respondsToSelector:@selector(textFieldDidEndEditing:)]) {
[_delegate textFieldDidEndEditing:textField];
}
-
- if (_textField.dataSource) {
- textField.text = @"";
- }
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
@@ -104,7 +100,7 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (!_textField.searchesAutomatically) {
[_textField search];
} else {
- [_textField resignFirstResponder];
+ [_textField performSelector:@selector(doneAction)];
}
}
return shouldReturn;
@@ -222,6 +218,7 @@ - (void)autoSearch {
[self search];
}
}
+
- (void)dispatchUpdate:(NSTimer*)timer {
_searchTimer = nil;
[self autoSearch];
@@ -253,6 +250,10 @@ - (void)screenAnimationDidStop {
- (void)doneAction {
[self resignFirstResponder];
+
+ if (self.dataSource) {
+ self.text = @"";
+ }
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -221,7 +221,7 @@ - (void)loadView {
CGFloat y = TTOSVersionIsAtLeast(3.0) ? 0 : -CHROME_HEIGHT;
CGRect innerFrame = CGRectMake(0, y,
screenFrame.size.width, screenFrame.size.height + CHROME_HEIGHT);
- UIView* innerView = [[UIView alloc] initWithFrame:innerFrame];
+ UIView* innerView = [[[UIView alloc] initWithFrame:innerFrame] autorelease];
innerView.backgroundColor = TTSTYLEVAR(backgroundColor);
[self.view addSubview:innerView];
View
@@ -206,6 +206,10 @@ - (void)cancel {
[[TTURLRequestQueue mainQueue] cancelRequest:self];
}
+- (NSURLRequest*)createNSURLRequest {
+ return [[TTURLRequestQueue mainQueue] createNSURLRequest:self url:nil];
+}
+
@end
//////////////////////////////////////////////////////////////////////////////////////////////////
View
@@ -87,31 +87,9 @@ - (void)connectToURL:(NSURL*)url {
TTLOG(@"Connecting to %@", _url);
TTNetworkRequestStarted();
- NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
- timeoutInterval:kTimeout];
- [urlRequest setValue:_queue.userAgent forHTTPHeaderField:@"User-Agent"];
+ TTURLRequest* request = _requests.count == 1 ? [_requests objectAtIndex:0] : nil;
+ NSURLRequest *urlRequest = [_queue createNSURLRequest:request url:url];
- if (_requests.count == 1) {
- TTURLRequest* request = [_requests objectAtIndex:0];
- [urlRequest setHTTPShouldHandleCookies:request.shouldHandleCookies];
-
- NSString* method = request.httpMethod;
- if (method) {
- [urlRequest setHTTPMethod:method];
- }
-
- NSString* contentType = request.contentType;
- if (contentType) {
- [urlRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
- }
-
- NSData* body = request.httpBody;
- if (body) {
- [urlRequest setHTTPBody:body];
- }
- }
-
_connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}
@@ -611,4 +589,36 @@ - (void)cancelAllRequests {
}
}
+- (NSURLRequest*)createNSURLRequest:(TTURLRequest*)request url:(NSURL*)url {
+ if (!url) {
+ url = [NSURL URLWithString:request.url];
+ }
+
+ NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
+ timeoutInterval:kTimeout];
+ [urlRequest setValue:self.userAgent forHTTPHeaderField:@"User-Agent"];
+
+ if (request) {
+ [urlRequest setHTTPShouldHandleCookies:request.shouldHandleCookies];
+
+ NSString* method = request.httpMethod;
+ if (method) {
+ [urlRequest setHTTPMethod:method];
+ }
+
+ NSString* contentType = request.contentType;
+ if (contentType) {
+ [urlRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
+ }
+
+ NSData* body = request.httpBody;
+ if (body) {
+ [urlRequest setHTTPBody:body];
+ }
+ }
+
+ return urlRequest;
+}
+
@end
View
@@ -169,6 +169,11 @@ - (NSURL*)url {
return _webView.request.URL;
}
+- (void)openRequest:(NSURLRequest*)request {
+ self.view;
+ [_webView loadRequest:request];
+}
+
- (void)setHeaderView:(UIView*)headerView {
if (headerView != _headerView) {
BOOL addingHeader = !_headerView && headerView;
@@ -195,9 +200,8 @@ - (void)setHeaderView:(UIView*)headerView {
}
- (void)openURL:(NSURL*)url {
- self.view;
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
- [_webView loadRequest:request];
+ [self openRequest:request];
}
@end
@@ -101,6 +101,8 @@
*/
- (void)cancel;
+- (NSURLRequest*)createNSURLRequest;
+
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -76,4 +76,9 @@
*/
- (void)cancelAllRequests;
+/**
+ * Creates a Cocoa URL request from a Three20 URL request.
+ */
+- (NSURLRequest*)createNSURLRequest:(TTURLRequest*)request url:(NSURL*)url;
+
@end
@@ -19,6 +19,7 @@
@property(nonatomic,retain) UIView* headerView;
- (void)openURL:(NSURL*)url;
+- (void)openRequest:(NSURLRequest*)request;
@end

0 comments on commit b5e86f3

Please sign in to comment.