在UITableView中,我从下面的代码中将_arrayMp3Link格式的数据下载到table.suppose中,在表中以行的形式抓取了一些数据
A
B
C
D
我希望每当我单击第一行时,意味着被抓取的数据将由didSelectRowAtIndexPath.what选择并复制到文本框中。如果我选择特定行的数据并将其复制到某个文本框中,则应执行此操作
-(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 { }
发布于 2012-09-29 18:46:39
不确定我是否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.
}
}https://stackoverflow.com/questions/12651993
复制相似问题