UIPickerView
insideを作成しようとしていますが、UITableViewCell
正常に動作します。UIProgressView
asのタグを設定しましたindexPath.row
。現在、3行UIProgressView
あり、ファイルをダウンロードするときにこれを使用していますNSURLConnection
メソッドをNSURLConnection
呼び出すと、connection:didReceiveData:
を一致させて進行状況を更新しようとしindexPath.row
ますが、最後の行だけが更新される理由がわかりません
私にお知らせください
- (void)download:(NSString*)rowId
{
NSURL *url;
if ([rowId intValue] == 0 ){
url = [NSURL URLWithString:@"http://192.168.0.29/iphone/video/video_10.mov"];
}
else if ([rowId intValue] == 1){
url = [NSURL URLWithString:@"http://192.168.0.29/iphone/video/video_10.mov"];
}
else if ([rowId intValue] == 2){
url = [NSURL URLWithString:@"http://192.168.0.29/iphone/video/video_10.mov"];
}
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
connection = nil;
}
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)recievedData {
if (data==nil) {
data = [[NSMutableData alloc] initWithCapacity:2048];
}
[data appendData:recievedData];
NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data length]];
float progress = [resourceLength floatValue] / [self.filesize floatValue];
NSLog(@"%d inside ",myId);
UIProgressView* downPreView = (UIProgressView*)[self.view viewWithTag:myId];
downPreView.progress = progress;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
//-------------------------------------------------------------------------------
{
static NSString *CellIdentifier = @"DownloadingCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
self.progressView = [[[UIProgressView alloc]initWithFrame:CGRectMake(80,70,170,15)]autorelease];
[self.progressView setProgressViewStyle:UIProgressViewStyleBar];
self.progressView.tag = indexPath.row;
self.progressView.progress = 0.0f;
myId = indexPath.row;
NSString *aid = [NSString stringWithFormat:@"%d",myId];
NSLog(@"%@",aid);
[cell.contentView addSubview:self.progressView];
[self performSelectorOnMainThread:@selector(download:) withObject:aid waitUntilDone:NO];
if (indexPath.row == 0)
{
cell.textLabel.text = @"Beautiful Dreamer";
cell.detailTextLabel.text = @"David Lehman";
cell.imageView.image = [UIImage imageNamed:@"download_poem_icon.png"];
}
else if (indexPath.row == 1)
{
cell.textLabel.text = @"Friends a Friendship";
cell.detailTextLabel.text = @"Denise Levertov";
cell.imageView.image = [UIImage imageNamed:@"download_poem_icon.png"];
}
else {
cell.textLabel.text = @"Love and Friendship";
cell.detailTextLabel.text = @"Dorianne Laux";
cell.imageView.image = [UIImage imageNamed:@"download_poem_icon.png"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}