Ho un pulsante e tabella. Ora voglio fare clic in modo tale che ogni volta che seleziono una riga in tableview
e prema il pulsante, quel particolare evento premere il tasto potrebbe accadere. Per questo, in primo luogo ho dare tag per ogni riga cioèClic su evento in UITableView
- (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];
}
// now tag each 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;
}
e ora nel mettere evento nel pulsante quando seleziono la riga e premere il tasto. Ma non ottenere le cose corrette.
(IBAction)doDownload:(id)sender {
// to select first row
if(cell.tag==1)
{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
È possibile ottenere la riga nella IBAction. Controlla la mia risposta qui: http://stackoverflow.com/a/12594183/1144632 – danielbeard