Showing
11 changed files
with
213 additions
and
162 deletions
| @@ -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 | + |
| 164 | - [[cell textLabel] setText:@"Use Keychain"]; | 148 | + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"]; |
| 165 | - useKeychain = [(ToggleCell *)cell toggle]; | 149 | + if (!cell) { |
| 166 | - break; | 150 | + cell = [InfoCell cell]; |
| 167 | - case 1: | 151 | + } |
| 168 | - [[cell textLabel] setText:@"Use Built-In Dialog"]; | 152 | + [[cell textLabel] setText:intro]; |
| 169 | - useBuiltInDialog = [(ToggleCell *)cell toggle]; | 153 | + [cell layoutSubviews]; |
| 170 | - break; | 154 | + |
| 155 | + } else if ([indexPath section] == 1) { | ||
| 156 | + cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"]; | ||
| 157 | + if (!cell) { | ||
| 158 | + cell = [ToggleCell cell]; | ||
| 159 | + if ([indexPath row] == 0) { | ||
| 160 | + [[cell textLabel] setText:@"Use Keychain"]; | ||
| 161 | + useKeychain = [(ToggleCell *)cell toggle]; | ||
| 162 | + } else { | ||
| 163 | + [[cell textLabel] setText:@"Use Built-In Dialog"]; | ||
| 164 | + useBuiltInDialog = [(ToggleCell *)cell toggle]; | ||
| 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; | 178 | + } |
| 179 | + [responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)]; | ||
| 180 | + | ||
| 181 | + | ||
| 179 | } | 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 | } |
| 136 | - } else { | ||
| 137 | - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease]; | ||
| 138 | - } | ||
| 139 | - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; | ||
| 140 | - | ||
| 141 | - int tablePadding = 40; | ||
| 142 | - int tableWidth = [tableView frame].size.width; | ||
| 143 | - if (tableWidth > 480) { // iPad | ||
| 144 | - tablePadding = 110; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - if ([indexPath section] == 1) { | ||
| 148 | [[cell textLabel] setText:@"Show Accurate Progress"]; | 153 | [[cell textLabel] setText:@"Show Accurate Progress"]; |
| 149 | accurateProgress = [(ToggleCell *)cell toggle]; | 154 | accurateProgress = [(ToggleCell *)cell toggle]; |
| 150 | - } else if ([indexPath section] == 2) { | ||
| 151 | 155 | ||
| 152 | - NSUInteger imageWidth = (tableWidth-tablePadding-20)/3; | 156 | + } else { |
| 153 | - NSUInteger imageHeight = imageWidth*0.66; | ||
| 154 | 157 | ||
| 155 | - imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease]; | 158 | + cell = [tableView dequeueReusableCellWithIdentifier:@"ImagesCell"]; |
| 156 | - [imageView1 setBackgroundColor:[UIColor grayColor]]; | ||
| 157 | - [cell addSubview:imageView1]; | ||
| 158 | 159 | ||
| 159 | - imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease]; | ||
| 160 | - [cell addSubview:imageProgressIndicator1]; | ||
| 161 | 160 | ||
| 162 | - UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease]; | 161 | + if (!cell) { |
| 163 | - if (tableWidth > 480) { | 162 | + |
| 164 | - [label setText:@"This image is 15KB in size"]; | 163 | + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImagesCell"] autorelease]; |
| 165 | - } else { | 164 | + |
| 166 | - [label setText:@"Img size: 15KB"]; | 165 | + imageView1 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease]; |
| 166 | + [imageView1 setBackgroundColor:[UIColor grayColor]]; | ||
| 167 | + [cell addSubview:imageView1]; | ||
| 168 | + | ||
| 169 | + imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 170 | + [cell addSubview:imageProgressIndicator1]; | ||
| 171 | + | ||
| 172 | + imageLabel1 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 173 | + if (tableWidth > 480) { | ||
| 174 | + [imageLabel1 setText:@"This image is 15KB in size"]; | ||
| 175 | + } else { | ||
| 176 | + [imageLabel1 setText:@"Img size: 15KB"]; | ||
| 177 | + } | ||
| 178 | + [imageLabel1 setTextAlignment:UITextAlignmentCenter]; | ||
| 179 | + [imageLabel1 setFont:[UIFont systemFontOfSize:11]]; | ||
| 180 | + [imageLabel1 setBackgroundColor:[UIColor clearColor]]; | ||
| 181 | + [cell addSubview:imageLabel1]; | ||
| 182 | + | ||
| 183 | + imageView2 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 184 | + [imageView2 setBackgroundColor:[UIColor grayColor]]; | ||
| 185 | + [cell addSubview:imageView2]; | ||
| 186 | + | ||
| 187 | + imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 188 | + [cell addSubview:imageProgressIndicator2]; | ||
| 189 | + | ||
| 190 | + imageLabel2 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 191 | + if (tableWidth > 480) { | ||
| 192 | + [imageLabel2 setText:@"This image is 176KB in size"]; | ||
| 193 | + } else { | ||
| 194 | + [imageLabel2 setText:@"Img size: 176KB"]; | ||
| 195 | + } | ||
| 196 | + [imageLabel2 setTextAlignment:UITextAlignmentCenter]; | ||
| 197 | + [imageLabel2 setFont:[UIFont systemFontOfSize:11]]; | ||
| 198 | + [imageLabel2 setBackgroundColor:[UIColor clearColor]]; | ||
| 199 | + [cell addSubview:imageLabel2]; | ||
| 200 | + | ||
| 201 | + imageView3 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 202 | + [imageView3 setBackgroundColor:[UIColor grayColor]]; | ||
| 203 | + [cell addSubview:imageView3]; | ||
| 204 | + | ||
| 205 | + imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 206 | + [cell addSubview:imageProgressIndicator3]; | ||
| 207 | + | ||
| 208 | + imageLabel3 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | ||
| 209 | + if (tableWidth > 480) { | ||
| 210 | + [imageLabel3 setText:@"This image is 1.4MB in size"]; | ||
| 211 | + } else { | ||
| 212 | + [imageLabel3 setText:@"Img size: 1.4MB"]; | ||
| 213 | + } | ||
| 214 | + [imageLabel3 setTextAlignment:UITextAlignmentCenter]; | ||
| 215 | + [imageLabel3 setFont:[UIFont systemFontOfSize:11]]; | ||
| 216 | + [imageLabel3 setBackgroundColor:[UIColor clearColor]]; | ||
| 217 | + [cell addSubview:imageLabel3]; | ||
| 218 | + | ||
| 167 | } | 219 | } |
| 168 | - [label setTextAlignment:UITextAlignmentCenter]; | 220 | + NSUInteger imageWidth = (tableWidth-tablePadding-20)/3; |
| 169 | - [label setFont:[UIFont systemFontOfSize:11]]; | 221 | + NSUInteger imageHeight = imageWidth*0.66; |
| 170 | - [label setBackgroundColor:[UIColor clearColor]]; | ||
| 171 | - [cell addSubview:label]; | ||
| 172 | - | ||
| 173 | - imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease]; | ||
| 174 | - [imageView2 setBackgroundColor:[UIColor grayColor]]; | ||
| 175 | - [cell addSubview:imageView2]; | ||
| 176 | 222 | ||
| 177 | - imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease]; | ||
| 178 | - [cell addSubview:imageProgressIndicator2]; | ||
| 179 | 223 | ||
| 180 | - label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease]; | 224 | + [imageView1 setFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)]; |
| 181 | - if (tableWidth > 480) { | 225 | + [imageProgressIndicator1 setFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)]; |
| 182 | - [label setText:@"This image is 176KB in size"]; | 226 | + [imageLabel1 setFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)]; |
| 183 | - } else { | ||
| 184 | - [label setText:@"Img size: 176KB"]; | ||
| 185 | - } | ||
| 186 | - [label setTextAlignment:UITextAlignmentCenter]; | ||
| 187 | - [label setFont:[UIFont systemFontOfSize:11]]; | ||
| 188 | - [label setBackgroundColor:[UIColor clearColor]]; | ||
| 189 | - [cell addSubview:label]; | ||
| 190 | 227 | ||
| 191 | - imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease]; | 228 | + [imageView2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)]; |
| 192 | - [imageView3 setBackgroundColor:[UIColor grayColor]]; | 229 | + [imageProgressIndicator2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)]; |
| 193 | - [cell addSubview:imageView3]; | 230 | + [imageLabel2 setFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)]; |
| 194 | 231 | ||
| 195 | - imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease]; | 232 | + [imageView3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)]; |
| 196 | - [cell addSubview:imageProgressIndicator3]; | 233 | + [imageProgressIndicator3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)]; |
| 197 | - | 234 | + [imageLabel3 setFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)]; |
| 198 | - label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease]; | ||
| 199 | - if (tableWidth > 480) { | ||
| 200 | - [label setText:@"This image is 1.4MB in size"]; | ||
| 201 | - } else { | ||
| 202 | - [label setText:@"Img size: 1.4MB"]; | ||
| 203 | - } | ||
| 204 | - [label setTextAlignment:UITextAlignmentCenter]; | ||
| 205 | - [label setFont:[UIFont systemFontOfSize:11]]; | ||
| 206 | - [label setBackgroundColor:[UIColor clearColor]]; | ||
| 207 | - [cell addSubview:label]; | ||
| 208 | - | ||
| 209 | } | 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,64 +80,69 @@ static NSString *intro = @"Demonstrates fetching a web page synchronously, the H | @@ -80,64 +80,69 @@ 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"]; |
| 109 | - if ([self request]) { | 92 | + if (!cell) { |
| 110 | - [urlField setText:[[[self request] url] absoluteString]]; | 93 | + cell = [InfoCell cell]; |
| 111 | - } else { | 94 | + } |
| 112 | - [urlField setText:@"http://allseeing-i.com"]; | 95 | + [[cell textLabel] setText:intro]; |
| 113 | - } | 96 | + [cell layoutSubviews]; |
| 114 | - UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | 97 | + |
| 115 | - [goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)]; | 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]; | ||
| 116 | [goButton setTitle:@"Go!" forState:UIControlStateNormal]; | 105 | [goButton setTitle:@"Go!" forState:UIControlStateNormal]; |
| 117 | - [goButton sizeToFit]; | ||
| 118 | [goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside]; | 106 | [goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside]; |
| 119 | [[cell contentView] addSubview:goButton]; | 107 | [[cell contentView] addSubview:goButton]; |
| 120 | - [[cell contentView] addSubview:urlField]; | 108 | + } |
| 121 | - break; | 109 | + [goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)]; |
| 122 | - case 2: | 110 | + [goButton sizeToFit]; |
| 123 | - | 111 | + [urlField setFrame:CGRectMake(10,12,tableWidth-tablePadding-50,20)]; |
| 124 | - responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease]; | 112 | + if ([self request]) { |
| 113 | + [urlField setText:[[[self request] url] absoluteString]]; | ||
| 114 | + } else { | ||
| 115 | + [urlField setText:@"http://allseeing-i.com"]; | ||
| 116 | + } | ||
| 117 | + | ||
| 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]; |
| 127 | - if (request) { | 126 | + } |
| 128 | - if ([request error]) { | 127 | + [responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)]; |
| 129 | - [responseField setText:[[request error] localizedDescription]]; | 128 | + if (request) { |
| 130 | - } else if ([request responseString]) { | 129 | + if ([request error]) { |
| 131 | - [responseField setText:[request responseString]]; | 130 | + [responseField setText:[[request error] localizedDescription]]; |
| 132 | - } | 131 | + } else if ([request responseString]) { |
| 132 | + [responseField setText:[request responseString]]; | ||
| 133 | } | 133 | } |
| 134 | - break; | 134 | + } |
| 135 | - case 3: | 135 | + |
| 136 | - key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]]; | 136 | + } else if ([indexPath section] == 3) { |
| 137 | - [[cell textLabel] setText:key]; | 137 | + cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"]; |
| 138 | - [[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]]; | 138 | + if (!cell) { |
| 139 | - break; | 139 | + cell = [DetailCell cell]; |
| 140 | + } | ||
| 141 | + NSString *key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]]; | ||
| 142 | + [[cell textLabel] setText:key]; | ||
| 143 | + [[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]]; | ||
| 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; |
| 122 | - | 116 | + if ([indexPath section] == 0) { |
| 123 | - case 2: | 117 | + cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"]; |
| 118 | + if (!cell) { | ||
| 119 | + cell = [InfoCell cell]; | ||
| 120 | + } | ||
| 121 | + [[cell textLabel] setText:intro]; | ||
| 122 | + [cell layoutSubviews]; | ||
| 123 | + | ||
| 124 | + | ||
| 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]; | ||
| 124 | 131 | ||
| 125 | - resultView = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,60)] autorelease]; | 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; | 135 | + } |
| 136 | + [resultView setFrame:CGRectMake(5,5,tableWidth-tablePadding,60)]; | ||
| 129 | } | 137 | } |
| 138 | + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; | ||
| 139 | + | ||
| 130 | return cell; | 140 | return cell; |
| 131 | } | 141 | } |
| 132 | 142 |
This diff was suppressed by a .gitattributes entry.
-
Please register or login to post a comment