如何从选定的单元格中分配 indexPath 中的数组元素
how to assign an array element in a indexPath from selected cells
我有一个带有声音列表的数组
NSArray *nameSound = @[@"alarm-1.wav",@"alarm-2.mp3",@"alarm-3.mp3",@"alarm-4.mp3",@"alarm-5.mp3"];
我有 TableView 有 5 个单元格,
如何将 TableView 的 indexPath 授予 nameSound 的元素
P.S。对不起我的英语
您必须借助以下方法
在 tableview
中传递该数组
//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]
}
它将帮助您将 nameSound
数据与 table 单元格绑定。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedVal = [nameSound objectAtIndex:indexPath.row];
// You can use this selectedVal
}
我有一个带有声音列表的数组
NSArray *nameSound = @[@"alarm-1.wav",@"alarm-2.mp3",@"alarm-3.mp3",@"alarm-4.mp3",@"alarm-5.mp3"];
我有 TableView 有 5 个单元格,
如何将 TableView 的 indexPath 授予 nameSound 的元素
P.S。对不起我的英语
您必须借助以下方法
在tableview
中传递该数组
//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]
}
它将帮助您将 nameSound
数据与 table 单元格绑定。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedVal = [nameSound objectAtIndex:indexPath.row];
// You can use this selectedVal
}