首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选择下载的UITABLEVIEW数据

选择下载的UITABLEVIEW数据
EN

Stack Overflow用户
提问于 2012-09-29 18:37:54
回答 1查看 94关注 0票数 1

UITableView中,我从下面的代码中将_arrayMp3Link格式的数据下载到table.suppose中,在表中以行的形式抓取了一些数据

A

B

C

D

我希望每当我单击第一行时,意味着被抓取的数据将由didSelectRowAtIndexPath.what选择并复制到文本框中。如果我选择特定行的数据并将其复制到某个文本框中,则应执行此操作

代码语言:javascript
复制
-(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];
    });
});

}

代码语言:javascript
复制
- (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;

}

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

代码语言:javascript
复制
-(void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

}

EN

回答 1

Stack Overflow用户

发布于 2012-09-29 18:46:39

不确定我是否100%得到了问题,但我认为你想做一些类似于下面的事情…

代码语言:javascript
复制
-(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.
     }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12651993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档