Ben Copsey

Clean up iPhone / iPad sample

Dismiss auth dialog
@@ -357,6 +357,7 @@ static const NSUInteger kDomainSection = 1; @@ -357,6 +357,7 @@ static const NSUInteger kDomainSection = 1;
357 [requestsNeedingAuthentication removeObject:theRequest]; 357 [requestsNeedingAuthentication removeObject:theRequest];
358 } 358 }
359 [self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:1]; 359 [self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:1];
  360 + [self dismiss];
360 } 361 }
361 362
362 #pragma mark table view data source 363 #pragma mark table view data source
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 24
25 // Automatically set on build 25 // Automatically set on build
26 26
27 -NSString *ASIHTTPRequestVersion = @"v1.6.2-68 2010-06-25"; 27 +NSString *ASIHTTPRequestVersion = @"v1.6.2-69 2010-06-26";
28 28
29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
30 30
@@ -135,48 +135,54 @@ static NSString *intro = @"Demonstrates fetching content from an area that requi @@ -135,48 +135,54 @@ static NSString *intro = @"Demonstrates fetching content from an area that requi
135 135
136 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 136 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
137 { 137 {
138 - UITableViewCell *cell;  
139 - if ([indexPath section] == 0) {  
140 - cell = [InfoCell cellWithDescription:intro];  
141 - } else if ([indexPath section] == 1) {  
142 - cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];  
143 - if (!cell) {  
144 - cell = [ToggleCell cell];  
145 - }  
146 - } else {  
147 - cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];  
148 - if (!cell) {  
149 - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];  
150 - }  
151 - }  
152 - [cell setSelectionStyle:UITableViewCellSelectionStyleNone];  
153 -  
154 int tablePadding = 40; 138 int tablePadding = 40;
155 int tableWidth = [tableView frame].size.width; 139 int tableWidth = [tableView frame].size.width;
156 if (tableWidth > 480) { // iPad 140 if (tableWidth > 480) { // iPad
157 tablePadding = 110; 141 tablePadding = 110;
158 } 142 }
159 143
160 - switch ([indexPath section]) { 144 +
161 - case 1: 145 + UITableViewCell *cell;
162 - switch ([indexPath row]) { 146 + if ([indexPath section] == 0) {
163 - case 0: 147 +
  148 + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
  149 + if (!cell) {
  150 + cell = [InfoCell cell];
  151 + }
  152 + [[cell textLabel] setText:intro];
  153 + [cell layoutSubviews];
  154 +
  155 + } else if ([indexPath section] == 1) {
  156 + cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
  157 + if (!cell) {
  158 + cell = [ToggleCell cell];
  159 + if ([indexPath row] == 0) {
164 [[cell textLabel] setText:@"Use Keychain"]; 160 [[cell textLabel] setText:@"Use Keychain"];
165 useKeychain = [(ToggleCell *)cell toggle]; 161 useKeychain = [(ToggleCell *)cell toggle];
166 - break; 162 + } else {
167 - case 1:  
168 [[cell textLabel] setText:@"Use Built-In Dialog"]; 163 [[cell textLabel] setText:@"Use Built-In Dialog"];
169 useBuiltInDialog = [(ToggleCell *)cell toggle]; 164 useBuiltInDialog = [(ToggleCell *)cell toggle];
170 - break;  
171 } 165 }
172 - break; 166 + }
173 - case 2: 167 +
174 - responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease]; 168 + } else if ([indexPath section] == 2) {
  169 +
  170 + cell = [tableView dequeueReusableCellWithIdentifier:@"Response"];
  171 + if (!cell) {
  172 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Response"] autorelease];
  173 +
  174 + responseField = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
175 [responseField setBackgroundColor:[UIColor clearColor]]; 175 [responseField setBackgroundColor:[UIColor clearColor]];
176 [responseField setText:@"Secret information will appear here if authentication succeeds"]; 176 [responseField setText:@"Secret information will appear here if authentication succeeds"];
177 [[cell contentView] addSubview:responseField]; 177 [[cell contentView] addSubview:responseField];
178 - break;  
179 } 178 }
  179 + [responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)];
  180 +
  181 +
  182 + }
  183 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  184 +
  185 +
180 return cell; 186 return cell;
181 } 187 }
182 188
@@ -12,6 +12,6 @@ @@ -12,6 +12,6 @@
12 @interface InfoCell : UITableViewCell { 12 @interface InfoCell : UITableViewCell {
13 13
14 } 14 }
15 -+ (id)cellWithDescription:(NSString *)description; 15 ++ (id)cell;
16 + (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth; 16 + (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth;
17 @end 17 @end
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 11
12 @implementation InfoCell 12 @implementation InfoCell
13 13
14 -+ (id)cellWithDescription:(NSString *)description 14 ++ (id)cell
15 { 15 {
16 InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease]; 16 InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease];
17 if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad 17 if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
@@ -21,8 +21,6 @@ @@ -21,8 +21,6 @@
21 } 21 }
22 [[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap]; 22 [[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap];
23 [[cell textLabel] setNumberOfLines:0]; 23 [[cell textLabel] setNumberOfLines:0];
24 - [[cell textLabel] setText:description];  
25 - [[cell textLabel] sizeToFit];  
26 24
27 if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad 25 if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
28 UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease]; 26 UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease];
@@ -22,6 +22,9 @@ @@ -22,6 +22,9 @@
22 UIProgressView *imageProgressIndicator1; 22 UIProgressView *imageProgressIndicator1;
23 UIProgressView *imageProgressIndicator2; 23 UIProgressView *imageProgressIndicator2;
24 UIProgressView *imageProgressIndicator3; 24 UIProgressView *imageProgressIndicator3;
  25 + UILabel *imageLabel1;
  26 + UILabel *imageLabel2;
  27 + UILabel *imageLabel3;
25 BOOL failed; 28 BOOL failed;
26 29
27 } 30 }
@@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
80 } 80 }
81 81
82 - (void)dealloc { 82 - (void)dealloc {
  83 + [progressIndicator release];
83 [networkQueue reset]; 84 [networkQueue reset];
84 [networkQueue release]; 85 [networkQueue release];
85 [super dealloc]; 86 [super dealloc];
@@ -115,7 +116,11 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI @@ -115,7 +116,11 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI
115 [goButton addTarget:self action:@selector(fetchThreeImages:) forControlEvents:UIControlEventTouchUpInside]; 116 [goButton addTarget:self action:@selector(fetchThreeImages:) forControlEvents:UIControlEventTouchUpInside];
116 [view addSubview:goButton]; 117 [view addSubview:goButton];
117 118
118 - progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease]; 119 + if (!progressIndicator) {
  120 + progressIndicator = [[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
  121 + } else {
  122 + [progressIndicator setFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
  123 + }
119 [view addSubview:progressIndicator]; 124 [view addSubview:progressIndicator];
120 125
121 return view; 126 return view;
@@ -125,88 +130,110 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI @@ -125,88 +130,110 @@ static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASI
125 130
126 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 131 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
127 { 132 {
  133 + int tablePadding = 40;
  134 + int tableWidth = [tableView frame].size.width;
  135 + if (tableWidth > 480) { // iPad
  136 + tablePadding = 110;
  137 + }
  138 +
128 UITableViewCell *cell; 139 UITableViewCell *cell;
129 if ([indexPath section] == 0) { 140 if ([indexPath section] == 0) {
130 - cell = [InfoCell cellWithDescription:intro]; 141 + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
  142 + if (!cell) {
  143 + cell = [InfoCell cell];
  144 + }
  145 + [[cell textLabel] setText:intro];
  146 + [cell layoutSubviews];
  147 +
131 } else if ([indexPath section] == 1) { 148 } else if ([indexPath section] == 1) {
132 cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"]; 149 cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
133 if (!cell) { 150 if (!cell) {
134 cell = [ToggleCell cell]; 151 cell = [ToggleCell cell];
135 } 152 }
  153 + [[cell textLabel] setText:@"Show Accurate Progress"];
  154 + accurateProgress = [(ToggleCell *)cell toggle];
  155 +
136 } else { 156 } else {
137 - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];  
138 - }  
139 - [cell setSelectionStyle:UITableViewCellSelectionStyleNone];  
140 157
141 - int tablePadding = 40; 158 + cell = [tableView dequeueReusableCellWithIdentifier:@"ImagesCell"];
142 - int tableWidth = [tableView frame].size.width;  
143 - if (tableWidth > 480) { // iPad  
144 - tablePadding = 110;  
145 - }  
146 159
147 - if ([indexPath section] == 1) {  
148 - [[cell textLabel] setText:@"Show Accurate Progress"];  
149 - accurateProgress = [(ToggleCell *)cell toggle];  
150 - } else if ([indexPath section] == 2) {  
151 160
152 - NSUInteger imageWidth = (tableWidth-tablePadding-20)/3; 161 + if (!cell) {
153 - NSUInteger imageHeight = imageWidth*0.66;  
154 162
155 - imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease]; 163 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImagesCell"] autorelease];
  164 +
  165 + imageView1 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
156 [imageView1 setBackgroundColor:[UIColor grayColor]]; 166 [imageView1 setBackgroundColor:[UIColor grayColor]];
157 [cell addSubview:imageView1]; 167 [cell addSubview:imageView1];
158 168
159 - imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease]; 169 + imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
160 [cell addSubview:imageProgressIndicator1]; 170 [cell addSubview:imageProgressIndicator1];
161 171
162 - UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease]; 172 + imageLabel1 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
163 if (tableWidth > 480) { 173 if (tableWidth > 480) {
164 - [label setText:@"This image is 15KB in size"]; 174 + [imageLabel1 setText:@"This image is 15KB in size"];
165 } else { 175 } else {
166 - [label setText:@"Img size: 15KB"]; 176 + [imageLabel1 setText:@"Img size: 15KB"];
167 } 177 }
168 - [label setTextAlignment:UITextAlignmentCenter]; 178 + [imageLabel1 setTextAlignment:UITextAlignmentCenter];
169 - [label setFont:[UIFont systemFontOfSize:11]]; 179 + [imageLabel1 setFont:[UIFont systemFontOfSize:11]];
170 - [label setBackgroundColor:[UIColor clearColor]]; 180 + [imageLabel1 setBackgroundColor:[UIColor clearColor]];
171 - [cell addSubview:label]; 181 + [cell addSubview:imageLabel1];
172 182
173 - imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease]; 183 + imageView2 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
174 [imageView2 setBackgroundColor:[UIColor grayColor]]; 184 [imageView2 setBackgroundColor:[UIColor grayColor]];
175 [cell addSubview:imageView2]; 185 [cell addSubview:imageView2];
176 186
177 - imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease]; 187 + imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
178 [cell addSubview:imageProgressIndicator2]; 188 [cell addSubview:imageProgressIndicator2];
179 189
180 - label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease]; 190 + imageLabel2 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
181 if (tableWidth > 480) { 191 if (tableWidth > 480) {
182 - [label setText:@"This image is 176KB in size"]; 192 + [imageLabel2 setText:@"This image is 176KB in size"];
183 } else { 193 } else {
184 - [label setText:@"Img size: 176KB"]; 194 + [imageLabel2 setText:@"Img size: 176KB"];
185 } 195 }
186 - [label setTextAlignment:UITextAlignmentCenter]; 196 + [imageLabel2 setTextAlignment:UITextAlignmentCenter];
187 - [label setFont:[UIFont systemFontOfSize:11]]; 197 + [imageLabel2 setFont:[UIFont systemFontOfSize:11]];
188 - [label setBackgroundColor:[UIColor clearColor]]; 198 + [imageLabel2 setBackgroundColor:[UIColor clearColor]];
189 - [cell addSubview:label]; 199 + [cell addSubview:imageLabel2];
190 200
191 - imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease]; 201 + imageView3 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
192 [imageView3 setBackgroundColor:[UIColor grayColor]]; 202 [imageView3 setBackgroundColor:[UIColor grayColor]];
193 [cell addSubview:imageView3]; 203 [cell addSubview:imageView3];
194 204
195 - imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease]; 205 + imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
196 [cell addSubview:imageProgressIndicator3]; 206 [cell addSubview:imageProgressIndicator3];
197 207
198 - label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease]; 208 + imageLabel3 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
199 if (tableWidth > 480) { 209 if (tableWidth > 480) {
200 - [label setText:@"This image is 1.4MB in size"]; 210 + [imageLabel3 setText:@"This image is 1.4MB in size"];
201 } else { 211 } else {
202 - [label setText:@"Img size: 1.4MB"]; 212 + [imageLabel3 setText:@"Img size: 1.4MB"];
203 } 213 }
204 - [label setTextAlignment:UITextAlignmentCenter]; 214 + [imageLabel3 setTextAlignment:UITextAlignmentCenter];
205 - [label setFont:[UIFont systemFontOfSize:11]]; 215 + [imageLabel3 setFont:[UIFont systemFontOfSize:11]];
206 - [label setBackgroundColor:[UIColor clearColor]]; 216 + [imageLabel3 setBackgroundColor:[UIColor clearColor]];
207 - [cell addSubview:label]; 217 + [cell addSubview:imageLabel3];
208 218
209 } 219 }
  220 + NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
  221 + NSUInteger imageHeight = imageWidth*0.66;
  222 +
  223 +
  224 + [imageView1 setFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)];
  225 + [imageProgressIndicator1 setFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)];
  226 + [imageLabel1 setFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)];
  227 +
  228 + [imageView2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)];
  229 + [imageProgressIndicator2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)];
  230 + [imageLabel2 setFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)];
  231 +
  232 + [imageView3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)];
  233 + [imageProgressIndicator3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)];
  234 + [imageLabel3 setFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)];
  235 + }
  236 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
210 return cell; 237 return cell;
211 } 238 }
212 239
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 ASIHTTPRequest *request; 14 ASIHTTPRequest *request;
15 UITextField *urlField; 15 UITextField *urlField;
16 UITextView *responseField; 16 UITextView *responseField;
  17 + UIButton *goButton;
17 18
18 } 19 }
19 - (IBAction)simpleURLFetch:(id)sender; 20 - (IBAction)simpleURLFetch:(id)sender;
@@ -80,50 +80,51 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H @@ -80,50 +80,51 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H
80 80
81 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 81 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
82 { 82 {
83 - UITableViewCell *cell;  
84 - if ([indexPath section] == 0) {  
85 - cell = [InfoCell cellWithDescription:intro];  
86 - } else if ([indexPath section] == 3) {  
87 - cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];  
88 - if (!cell) {  
89 - cell = [DetailCell cell];  
90 - }  
91 - } else {  
92 - cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];  
93 - if (!cell) {  
94 - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];  
95 - }  
96 - }  
97 - [cell setSelectionStyle:UITableViewCellSelectionStyleNone];  
98 - NSString *key;  
99 -  
100 int tablePadding = 40; 83 int tablePadding = 40;
101 int tableWidth = [tableView frame].size.width; 84 int tableWidth = [tableView frame].size.width;
102 if (tableWidth > 480) { // iPad 85 if (tableWidth > 480) { // iPad
103 tablePadding = 110; 86 tablePadding = 110;
104 } 87 }
105 88
106 - switch ([indexPath section]) { 89 + UITableViewCell *cell;
107 - case 1: 90 + if ([indexPath section] == 0) {
108 - urlField = [[[UITextField alloc] initWithFrame:CGRectMake(10,12,tableWidth-tablePadding-50,20)] autorelease]; 91 + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
  92 + if (!cell) {
  93 + cell = [InfoCell cell];
  94 + }
  95 + [[cell textLabel] setText:intro];
  96 + [cell layoutSubviews];
  97 +
  98 + } else if ([indexPath section] == 1) {
  99 + cell = [tableView dequeueReusableCellWithIdentifier:@"URLCell"];
  100 + if (!cell) {
  101 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"URLCell"] autorelease];
  102 + urlField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease];
  103 + [[cell contentView] addSubview:urlField];
  104 + goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  105 + [goButton setTitle:@"Go!" forState:UIControlStateNormal];
  106 + [goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside];
  107 + [[cell contentView] addSubview:goButton];
  108 + }
  109 + [goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)];
  110 + [goButton sizeToFit];
  111 + [urlField setFrame:CGRectMake(10,12,tableWidth-tablePadding-50,20)];
109 if ([self request]) { 112 if ([self request]) {
110 [urlField setText:[[[self request] url] absoluteString]]; 113 [urlField setText:[[[self request] url] absoluteString]];
111 } else { 114 } else {
112 [urlField setText:@"http://allseeing-i.com"]; 115 [urlField setText:@"http://allseeing-i.com"];
113 } 116 }
114 - UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
115 - [goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)];  
116 - [goButton setTitle:@"Go!" forState:UIControlStateNormal];  
117 - [goButton sizeToFit];  
118 - [goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside];  
119 - [[cell contentView] addSubview:goButton];  
120 - [[cell contentView] addSubview:urlField];  
121 - break;  
122 - case 2:  
123 117
124 - responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease]; 118 +
  119 + } else if ([indexPath section] == 2) {
  120 + cell = [tableView dequeueReusableCellWithIdentifier:@"ResponseCell"];
  121 + if (!cell) {
  122 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ResponseCell"] autorelease];
  123 + responseField = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
125 [responseField setBackgroundColor:[UIColor clearColor]]; 124 [responseField setBackgroundColor:[UIColor clearColor]];
126 [[cell contentView] addSubview:responseField]; 125 [[cell contentView] addSubview:responseField];
  126 + }
  127 + [responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)];
127 if (request) { 128 if (request) {
128 if ([request error]) { 129 if ([request error]) {
129 [responseField setText:[[request error] localizedDescription]]; 130 [responseField setText:[[request error] localizedDescription]];
@@ -131,13 +132,17 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H @@ -131,13 +132,17 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H
131 [responseField setText:[request responseString]]; 132 [responseField setText:[request responseString]];
132 } 133 }
133 } 134 }
134 - break; 135 +
135 - case 3: 136 + } else if ([indexPath section] == 3) {
136 - key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]]; 137 + cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];
  138 + if (!cell) {
  139 + cell = [DetailCell cell];
  140 + }
  141 + NSString *key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]];
137 [[cell textLabel] setText:key]; 142 [[cell textLabel] setText:key];
138 [[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]]; 143 [[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]];
139 - break;  
140 } 144 }
  145 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
141 return cell; 146 return cell;
142 } 147 }
143 148
@@ -59,6 +59,7 @@ @@ -59,6 +59,7 @@
59 { 59 {
60 [request cancel]; 60 [request cancel];
61 [request release]; 61 [request release];
  62 + [progressIndicator release];
62 [super dealloc]; 63 [super dealloc];
63 } 64 }
64 65
@@ -91,7 +92,11 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload @@ -91,7 +92,11 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload
91 [goButton addTarget:self action:@selector(performLargeUpload:) forControlEvents:UIControlEventTouchUpInside]; 92 [goButton addTarget:self action:@selector(performLargeUpload:) forControlEvents:UIControlEventTouchUpInside];
92 [view addSubview:goButton]; 93 [view addSubview:goButton];
93 94
94 - progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease]; 95 + if (!progressIndicator) {
  96 + progressIndicator = [[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
  97 + } else {
  98 + [progressIndicator setFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
  99 + }
95 [view addSubview:progressIndicator]; 100 [view addSubview:progressIndicator];
96 101
97 return view; 102 return view;
@@ -101,32 +106,37 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload @@ -101,32 +106,37 @@ static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload
101 106
102 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 107 - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
103 { 108 {
104 - UITableViewCell *cell;  
105 - if ([indexPath section] == 0) {  
106 - cell = [InfoCell cellWithDescription:intro];  
107 - } else {  
108 - cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];  
109 - if (!cell) {  
110 - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];  
111 - }  
112 - }  
113 - [cell setSelectionStyle:UITableViewCellSelectionStyleNone];  
114 -  
115 int tablePadding = 40; 109 int tablePadding = 40;
116 int tableWidth = [tableView frame].size.width; 110 int tableWidth = [tableView frame].size.width;
117 if (tableWidth > 480) { // iPad 111 if (tableWidth > 480) { // iPad
118 tablePadding = 110; 112 tablePadding = 110;
119 } 113 }
120 114
121 - switch ([indexPath section]) { 115 + UITableViewCell *cell;
  116 + if ([indexPath section] == 0) {
  117 + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
  118 + if (!cell) {
  119 + cell = [InfoCell cell];
  120 + }
  121 + [[cell textLabel] setText:intro];
  122 + [cell layoutSubviews];
122 123
123 - case 2:  
124 124
125 - resultView = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,60)] autorelease]; 125 + } else if ([indexPath section] == 1) {
  126 + return nil;
  127 + } else if ([indexPath section] == 2) {
  128 + cell = [tableView dequeueReusableCellWithIdentifier:@"Response"];
  129 + if (!cell) {
  130 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Response"] autorelease];
  131 +
  132 + resultView = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
126 [resultView setBackgroundColor:[UIColor clearColor]]; 133 [resultView setBackgroundColor:[UIColor clearColor]];
127 [[cell contentView] addSubview:resultView]; 134 [[cell contentView] addSubview:resultView];
128 - break;  
129 } 135 }
  136 + [resultView setFrame:CGRectMake(5,5,tableWidth-tablePadding,60)];
  137 + }
  138 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  139 +
130 return cell; 140 return cell;
131 } 141 }
132 142
This diff was suppressed by a .gitattributes entry.