1

UITableView我通过下载_arrayMp3Link从下面的代码到表中的数据来翻录一些数据。假设它在表中的行中翻录为

A

B

C

D

我希望每当我单击第一行时,意味着被翻录的数据将被选择并复制到文本框。didSelectRowAtIndexPath我应该怎么做才能选择特定行的数据并复制到某个文本框中

-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[_hubView showWithIndicatorAndText:@"Ripping files" animated:YES];

//Rip mp3

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSString *regexStr =  @"(<a.* href=[\"'])(.*\\.mp[34][^\"]*)[\"'](.*</a>)";
    NSError *error = nil;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:0 error:&error];

    if (((regex == nil) && (error != nil)) || _htmlString == nil){
        NSLog(@"Error");
    } else {
        listUrl = [NSMutableArray array];

        [regex enumerateMatchesInString:_htmlString 
                                options:0 
                                  range:NSMakeRange(0, _htmlString.length) 
                             usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
                                 if (result != nil){
                                     // iterate ranges

                               for (int i = 0; i < [result numberOfRanges]; i++) {
                               NSRange range = [result rangeAtIndex:i];
                           NSLog(@"%d,%d group #%d: %@", range.location, range.length, i, (range.length == 0 ? @"--" : [_htmlString substringWithRange:range]));
                                         if (i == 2) {
               if ([[_htmlString substringWithRange:range] hasSuffix:@".mp3"]) {
                 [listUrl addObject:[_htmlString substringWithRange:range]];
                      NSLog(@"%@", [_htmlString substringWithRange:range]);
                                             }
                                         }

                                         // Text a
                                         // Title href
                                     // Name file
                                 }
                                 } else {
                                     NSLog(@"NULL");
                                 }

        }];

        self.arrayMp3Link = [NSArray arrayWithArray:listUrl];
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [_tableView reloadData];
        [_hubView hideAnimated];
    });
});

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *LabelCellIdentifier = @"cell";
UITableViewCell *cell;

cell = [tableView dequeueReusableCellWithIdentifier:LabelCellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LabelCellIdentifier];



}

if (indexPath.row <= [_arrayMp3Link count]) {

    cell.textLabel.text = [_arrayMp3Link objectAtIndex:indexPath.row];

}

NSInteger count = 1;
for (NSInteger i = 0; i < indexPath.section; i++) {
    count += [[tableView dataSource] tableView:tableView numberOfRowsInSection:i];
}
count += indexPath.row;
// dequeue, create and configure...
cell.tag = count;



return cell;

}

// 这里我想要我没有得到的代码。

-(void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

}

4

1 回答 1

0

不确定我是否 100% 得到这个问题,但我认为你想做类似于下面的事情......

-(void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Do something with the first row
     if(indexPath.row == 0){
          yourTextView.text = [_arrayMp3Link objectAtIndex:indexPath.row];
     } else {
          // Do something else.
     }

}
于 2012-09-29T10:46:39.430 回答