-1

I have an array with sound list

NSArray *nameSound = @[@"alarm-1.wav",@"alarm-2.mp3",@"alarm-3.mp3",@"alarm-4.mp3",@"alarm-5.mp3"];

And I have TableView with 5 cells,

enter image description here

How award for indexPath from TableView to element from nameSound

P.S. Sorry for my English

Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40

2 Answers2

1

You have to pass that array in tableview with the help of below methods

//pass your array count for cell numbers
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [nameSound count];
}

//For Cell creation
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];

    cell.textLabel.text = [nameSound objectAtIndex:indexPath.row];
    return cell;
}

//Did Select row will get in below method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *selectedSound = [nameSound objectAtIndex:indexPath.row]
}

it will help you to bind nameSound data with table cell.

Igor Bidiniuc
  • 1,540
  • 1
  • 16
  • 27
CodeChanger
  • 7,953
  • 5
  • 49
  • 80
0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

       NSString *selectedVal = [nameSound objectAtIndex:indexPath.row];
       // You can use this selectedVal 

}
Dharani
  • 44
  • 8