【问题标题】:Selecting UITABLEVIEW data which is downloaded选择下载的 UITABLEVIEW 数据
【发布时间】:2012-09-29 10:37:54
【问题描述】:

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 { 

}

【问题讨论】:

    标签: iphone objective-c ios uitableview


    【解决方案1】:

    不确定我是否 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.
         }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多