Ben Copsey

Clean up iPhone / iPad sample

Dismiss auth dialog
... ... @@ -357,6 +357,7 @@ static const NSUInteger kDomainSection = 1;
[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 @@ static NSString *intro = @"Demonstrates fetching content from an area that requi
- (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:
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];
break;
case 1:
} else {
[[cell textLabel] setText:@"Use Built-In Dialog"];
useBuiltInDialog = [(ToggleCell *)cell toggle];
break;
}
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 @@
}
[[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)dealloc {
[progressIndicator release];
[networkQueue reset];
[networkQueue release];
[super dealloc];
... ... @@ -115,7 +116,11 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI
[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 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI
- (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];
}
[[cell textLabel] setText:@"Show Accurate Progress"];
accurateProgress = [(ToggleCell *)cell toggle];
} 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;
}
cell = [tableView dequeueReusableCellWithIdentifier:@"ImagesCell"];
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;
if (!cell) {
imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease];
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:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease];
imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator1];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease];
imageLabel1 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 15KB in size"];
[imageLabel1 setText:@"This image is 15KB in size"];
} else {
[label setText:@"Img size: 15KB"];
[imageLabel1 setText:@"Img size: 15KB"];
}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];
[imageLabel1 setTextAlignment:UITextAlignmentCenter];
[imageLabel1 setFont:[UIFont systemFontOfSize:11]];
[imageLabel1 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel1];
imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease];
imageView2 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[imageView2 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView2];
imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease];
imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator2];
label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease];
imageLabel2 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 176KB in size"];
[imageLabel2 setText:@"This image is 176KB in size"];
} else {
[label setText:@"Img size: 176KB"];
[imageLabel2 setText:@"Img size: 176KB"];
}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];
[imageLabel2 setTextAlignment:UITextAlignmentCenter];
[imageLabel2 setFont:[UIFont systemFontOfSize:11]];
[imageLabel2 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel2];
imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease];
imageView3 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[imageView3 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView3];
imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease];
imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator3];
label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease];
imageLabel3 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 1.4MB in size"];
[imageLabel3 setText:@"This image is 1.4MB in size"];
} else {
[label setText:@"Img size: 1.4MB"];
[imageLabel3 setText:@"Img size: 1.4MB"];
}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];
[imageLabel3 setTextAlignment:UITextAlignmentCenter];
[imageLabel3 setFont:[UIFont systemFontOfSize:11]];
[imageLabel3 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel3];
}
NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
NSUInteger imageHeight = imageWidth*0.66;
[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)];
[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)];
[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;
... ...
... ... @@ -80,50 +80,51 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if ([indexPath section] == 0) {
cell = [InfoCell cellWithDescription:intro];
} else if ([indexPath section] == 3) {
cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];
if (!cell) {
cell = [DetailCell cell];
}
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
}
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
NSString *key;
int tablePadding = 40;
int tableWidth = [tableView frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
}
switch ([indexPath section]) {
case 1:
urlField = [[[UITextField alloc] initWithFrame:CGRectMake(10,12,tableWidth-tablePadding-50,20)] autorelease];
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:@"URLCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"URLCell"] autorelease];
urlField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease];
[[cell contentView] addSubview:urlField];
goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[goButton setTitle:@"Go!" forState:UIControlStateNormal];
[goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside];
[[cell contentView] addSubview:goButton];
}
[goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)];
[goButton sizeToFit];
[urlField setFrame:CGRectMake(10,12,tableWidth-tablePadding-50,20)];
if ([self request]) {
[urlField setText:[[[self request] url] absoluteString]];
} else {
[urlField setText:@"http://allseeing-i.com"];
}
UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)];
[goButton setTitle:@"Go!" forState:UIControlStateNormal];
[goButton sizeToFit];
[goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside];
[[cell contentView] addSubview:goButton];
[[cell contentView] addSubview:urlField];
break;
case 2:
responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease];
} else if ([indexPath section] == 2) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ResponseCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ResponseCell"] autorelease];
responseField = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
[responseField setBackgroundColor:[UIColor clearColor]];
[[cell contentView] addSubview:responseField];
}
[responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)];
if (request) {
if ([request error]) {
[responseField setText:[[request error] localizedDescription]];
... ... @@ -131,13 +132,17 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H
[responseField setText:[request responseString]];
}
}
break;
case 3:
key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]];
} else if ([indexPath section] == 3) {
cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];
if (!cell) {
cell = [DetailCell cell];
}
NSString *key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:key];
[[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]];
break;
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
... ...
... ... @@ -59,6 +59,7 @@
{
[request cancel];
[request release];
[progressIndicator release];
[super dealloc];
}
... ... @@ -91,7 +92,11 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload
[goButton addTarget:self action:@selector(performLargeUpload:) 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;
... ... @@ -101,32 +106,37 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if ([indexPath section] == 0) {
cell = [InfoCell cellWithDescription:intro];
} 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]) {
UITableViewCell *cell;
if ([indexPath section] == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
if (!cell) {
cell = [InfoCell cell];
}
[[cell textLabel] setText:intro];
[cell layoutSubviews];
case 2:
resultView = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,60)] autorelease];
} else if ([indexPath section] == 1) {
return nil;
} else if ([indexPath section] == 2) {
cell = [tableView dequeueReusableCellWithIdentifier:@"Response"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Response"] autorelease];
resultView = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
[resultView setBackgroundColor:[UIColor clearColor]];
[[cell contentView] addSubview:resultView];
break;
}
[resultView setFrame:CGRectMake(5,5,tableWidth-tablePadding,60)];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
... ...
This diff was suppressed by a .gitattributes entry.