Mam przycisk i tabelę. Teraz chcę kliknąć w taki sposób, że Ilekroć wybiorę dowolny wiersz w tableview
i naciśnij przycisk, nastąpi to konkretne wydarzenie naciśnięcia przycisku. W tym celu, po pierwsze mam dać tag do każdego wiersza tjKliknięcie zdarzenia w widoku 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;
}
a teraz w oddanie zdarzenie w przycisk po zaznaczeniu wiersza i naciśnij przycisk moje. Ale nie dostaniesz poprawnych rzeczy.
(IBAction)doDownload:(id)sender {
// to select first row
if(cell.tag==1)
{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
można uzyskać wiersz w IBAction. Sprawdź moją odpowiedź tutaj: http://stackoverflow.com/a/12594183/1144632 – danielbeard