Tôi có một nút và Bảng. Bây giờ tôi muốn nhấp vào theo cách như vậy Bất cứ khi nào tôi chọn bất kỳ hàng nào trong tableview
và nhấn nút, sự kiện nhấn nút cụ thể đó sẽ xảy ra. Cho rằng, trước hết tôi đã cung cấp cho thẻ để mỗi hàng tức làNhấp vào Sự kiện trong 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;
}
và bây giờ trong việc đưa sự kiện trong nút khi tôi chọn hàng và nhấn nút của tôi. Nhưng không nhận được những điều đúng.
(IBAction)doDownload:(id)sender {
// to select first row
if(cell.tag==1)
{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
Bạn có thể nhận được hàng trong IBAction. Kiểm tra câu trả lời của tôi ở đây: http://stackoverflow.com/a/12594183/1144632 – danielbeard