Permalink
Browse files

Clean up iPhone / iPad sample

Dismiss auth dialog
  • Loading branch information...
1 parent aea86b9 commit 1247da7ebb1e5a6e96e486d1b7d3fbc15e9e6bb7 @pokeb committed Jun 26, 2010
@@ -357,6 +357,7 @@ - (void)loginWithCredentialsFromDialog:(id)sender
[requestsNeedingAuthentication removeObject:theRequest];
}
[self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:1];
+ [self dismiss];
}
#pragma mark table view data source
@@ -24,7 +24,7 @@
// Automatically set on build
-NSString *ASIHTTPRequestVersion = @"v1.6.2-68 2010-06-25";
+NSString *ASIHTTPRequestVersion = @"v1.6.2-69 2010-06-26";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
@@ -135,48 +135,54 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- UITableViewCell *cell;
- if ([indexPath section] == 0) {
- cell = [InfoCell cellWithDescription:intro];
- } else if ([indexPath section] == 1) {
- cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
- if (!cell) {
- cell = [ToggleCell cell];
- }
- } else {
- cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
- if (!cell) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
- }
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
-
int tablePadding = 40;
int tableWidth = [tableView frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
}
- switch ([indexPath section]) {
- case 1:
- switch ([indexPath row]) {
- case 0:
- [[cell textLabel] setText:@"Use Keychain"];
- useKeychain = [(ToggleCell *)cell toggle];
- break;
- case 1:
- [[cell textLabel] setText:@"Use Built-In Dialog"];
- useBuiltInDialog = [(ToggleCell *)cell toggle];
- break;
+
+ UITableViewCell *cell;
+ if ([indexPath section] == 0) {
+
+ cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
+ if (!cell) {
+ cell = [InfoCell cell];
+ }
+ [[cell textLabel] setText:intro];
+ [cell layoutSubviews];
+
+ } else if ([indexPath section] == 1) {
+ cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
+ if (!cell) {
+ cell = [ToggleCell cell];
+ if ([indexPath row] == 0) {
+ [[cell textLabel] setText:@"Use Keychain"];
+ useKeychain = [(ToggleCell *)cell toggle];
+ } else {
+ [[cell textLabel] setText:@"Use Built-In Dialog"];
+ useBuiltInDialog = [(ToggleCell *)cell toggle];
}
- break;
- case 2:
- responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease];
+ }
+
+ } else if ([indexPath section] == 2) {
+
+ cell = [tableView dequeueReusableCellWithIdentifier:@"Response"];
+ if (!cell) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Response"] autorelease];
+
+ responseField = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
[responseField setBackgroundColor:[UIColor clearColor]];
[responseField setText:@"Secret information will appear here if authentication succeeds"];
[[cell contentView] addSubview:responseField];
- break;
+ }
+ [responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)];
+
+
}
+ [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
+
+
return cell;
}
@@ -12,6 +12,6 @@
@interface InfoCell : UITableViewCell {
}
-+ (id)cellWithDescription:(NSString *)description;
++ (id)cell;
+ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth;
@end
@@ -11,7 +11,7 @@
@implementation InfoCell
-+ (id)cellWithDescription:(NSString *)description
++ (id)cell
{
InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease];
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
@@ -21,8 +21,6 @@ + (id)cellWithDescription:(NSString *)description
}
[[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap];
[[cell textLabel] setNumberOfLines:0];
- [[cell textLabel] setText:description];
- [[cell textLabel] sizeToFit];
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease];
@@ -22,6 +22,9 @@
UIProgressView *imageProgressIndicator1;
UIProgressView *imageProgressIndicator2;
UIProgressView *imageProgressIndicator3;
+ UILabel *imageLabel1;
+ UILabel *imageLabel2;
+ UILabel *imageLabel3;
BOOL failed;
}
@@ -80,6 +80,7 @@ - (void)imageFetchFailed:(ASIHTTPRequest *)request
}
- (void)dealloc {
+ [progressIndicator release];
[networkQueue reset];
[networkQueue release];
[super dealloc];
@@ -115,7 +116,11 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte
[goButton addTarget:self action:@selector(fetchThreeImages:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:goButton];
- progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease];
+ if (!progressIndicator) {
+ progressIndicator = [[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
+ } else {
+ [progressIndicator setFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
+ }
[view addSubview:progressIndicator];
return view;
@@ -125,88 +130,110 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
+ int tablePadding = 40;
+ int tableWidth = [tableView frame].size.width;
+ if (tableWidth > 480) { // iPad
+ tablePadding = 110;
+ }
+
UITableViewCell *cell;
if ([indexPath section] == 0) {
- cell = [InfoCell cellWithDescription:intro];
+ cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
+ if (!cell) {
+ cell = [InfoCell cell];
+ }
+ [[cell textLabel] setText:intro];
+ [cell layoutSubviews];
+
} else if ([indexPath section] == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
if (!cell) {
cell = [ToggleCell cell];
}
- } else {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
-
- int tablePadding = 40;
- int tableWidth = [tableView frame].size.width;
- if (tableWidth > 480) { // iPad
- tablePadding = 110;
- }
-
- if ([indexPath section] == 1) {
[[cell textLabel] setText:@"Show Accurate Progress"];
accurateProgress = [(ToggleCell *)cell toggle];
- } else if ([indexPath section] == 2) {
- NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
- NSUInteger imageHeight = imageWidth*0.66;
+ } else {
- imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease];
- [imageView1 setBackgroundColor:[UIColor grayColor]];
- [cell addSubview:imageView1];
+ cell = [tableView dequeueReusableCellWithIdentifier:@"ImagesCell"];
- imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease];
- [cell addSubview:imageProgressIndicator1];
- UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease];
- if (tableWidth > 480) {
- [label setText:@"This image is 15KB in size"];
- } else {
- [label setText:@"Img size: 15KB"];
+ if (!cell) {
+
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImagesCell"] autorelease];
+
+ imageView1 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
+ [imageView1 setBackgroundColor:[UIColor grayColor]];
+ [cell addSubview:imageView1];
+
+ imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
+ [cell addSubview:imageProgressIndicator1];
+
+ imageLabel1 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
+ if (tableWidth > 480) {
+ [imageLabel1 setText:@"This image is 15KB in size"];
+ } else {
+ [imageLabel1 setText:@"Img size: 15KB"];
+ }
+ [imageLabel1 setTextAlignment:UITextAlignmentCenter];
+ [imageLabel1 setFont:[UIFont systemFontOfSize:11]];
+ [imageLabel1 setBackgroundColor:[UIColor clearColor]];
+ [cell addSubview:imageLabel1];
+
+ imageView2 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
+ [imageView2 setBackgroundColor:[UIColor grayColor]];
+ [cell addSubview:imageView2];
+
+ imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
+ [cell addSubview:imageProgressIndicator2];
+
+ imageLabel2 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
+ if (tableWidth > 480) {
+ [imageLabel2 setText:@"This image is 176KB in size"];
+ } else {
+ [imageLabel2 setText:@"Img size: 176KB"];
+ }
+ [imageLabel2 setTextAlignment:UITextAlignmentCenter];
+ [imageLabel2 setFont:[UIFont systemFontOfSize:11]];
+ [imageLabel2 setBackgroundColor:[UIColor clearColor]];
+ [cell addSubview:imageLabel2];
+
+ imageView3 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
+ [imageView3 setBackgroundColor:[UIColor grayColor]];
+ [cell addSubview:imageView3];
+
+ imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
+ [cell addSubview:imageProgressIndicator3];
+
+ imageLabel3 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
+ if (tableWidth > 480) {
+ [imageLabel3 setText:@"This image is 1.4MB in size"];
+ } else {
+ [imageLabel3 setText:@"Img size: 1.4MB"];
+ }
+ [imageLabel3 setTextAlignment:UITextAlignmentCenter];
+ [imageLabel3 setFont:[UIFont systemFontOfSize:11]];
+ [imageLabel3 setBackgroundColor:[UIColor clearColor]];
+ [cell addSubview:imageLabel3];
+
}
- [label setTextAlignment:UITextAlignmentCenter];
- [label setFont:[UIFont systemFontOfSize:11]];
- [label setBackgroundColor:[UIColor clearColor]];
- [cell addSubview:label];
-
- imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease];
- [imageView2 setBackgroundColor:[UIColor grayColor]];
- [cell addSubview:imageView2];
+ NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
+ NSUInteger imageHeight = imageWidth*0.66;
- imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease];
- [cell addSubview:imageProgressIndicator2];
- label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease];
- if (tableWidth > 480) {
- [label setText:@"This image is 176KB in size"];
- } else {
- [label setText:@"Img size: 176KB"];
- }
- [label setTextAlignment:UITextAlignmentCenter];
- [label setFont:[UIFont systemFontOfSize:11]];
- [label setBackgroundColor:[UIColor clearColor]];
- [cell addSubview:label];
+ [imageView1 setFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)];
+ [imageProgressIndicator1 setFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)];
+ [imageLabel1 setFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)];
- imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease];
- [imageView3 setBackgroundColor:[UIColor grayColor]];
- [cell addSubview:imageView3];
+ [imageView2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)];
+ [imageProgressIndicator2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)];
+ [imageLabel2 setFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)];
- imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease];
- [cell addSubview:imageProgressIndicator3];
-
- label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease];
- if (tableWidth > 480) {
- [label setText:@"This image is 1.4MB in size"];
- } else {
- [label setText:@"Img size: 1.4MB"];
- }
- [label setTextAlignment:UITextAlignmentCenter];
- [label setFont:[UIFont systemFontOfSize:11]];
- [label setBackgroundColor:[UIColor clearColor]];
- [cell addSubview:label];
-
+ [imageView3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)];
+ [imageProgressIndicator3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)];
+ [imageLabel3 setFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)];
}
+ [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
@@ -14,6 +14,7 @@
ASIHTTPRequest *request;
UITextField *urlField;
UITextView *responseField;
+ UIButton *goButton;
}
- (IBAction)simpleURLFetch:(id)sender;
Oops, something went wrong.

0 comments on commit 1247da7

Please sign in to comment.