[英]How to pass the properties of data to anotherViewController?(StoryBoard)
我想在选择一个tableviewcell之后传递数据的属性。请指导我。我已经设置了detailviewcontroller.DataArray是detailviewcontroller中的mutablearray.peripheralManager是我的NSbject.Peripheral是我的设备。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
peripheralManager=[[PeripheralManager alloc]init];
self.MeBle.enabled=NO;
device=[[NSMutableArray alloc]init];
}
- (void)peripheralManagerDidConnectPeripheral:(PeripheralManager *)peripheral
{
NSLog(@"%@",peripheral.deviceName);
[device addObject:[NSString stringWithFormat:@" %@ ",peripheral.deviceName]];
// [device addObject:peripheral];
[self.deviceTable reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell==nil)
{
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text=[device objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//DetailViewController *detail=[self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
// [self.navigationController pushViewController:detail animated:YES];
//[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"TableDetails"]) {
DetailViewController *detail=segue.destinationViewController;
detail.dataArray=device;
}
}
在prepareForSegue中,您应该获得当前的选择索引:
NSIndexPath *indexPath = [self.deviceTable indexPathForCell:sender];
现在,您可以只将此索引传递给目标控制器,也可以将其传递给您当前数组中的特定对象。
detail.idx = [indexPath row];
编辑:那里你不需要实现
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
就在
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
更改为此:
detailViewObject.objCurrentDevice=[device objectAtIndex:[[self.deviceTable indexPathForCell:sender] row]];
在界面构建器中,查看seague运行时属性部分,可以创建多个样式相同但标识符不同的单元格,然后cellForRowAtIndexPath按行返回单元格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.