Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TableView Indexath.row不可分配_Ios_Uitableview_Tableview - Fatal编程技术网

Ios TableView Indexath.row不可分配

Ios TableView Indexath.row不可分配,ios,uitableview,tableview,Ios,Uitableview,Tableview,我想将tableView indexPath分配给视图控制器变量之一。然而,对我来说很奇怪,它指定了其中一个,无论我选择哪一行,它总是指定0。 正如您在下面的代码中看到的,iVC.virdsection=indexPath.row工作得非常好,但sVC2.evradID=indexPath.row始终为0 // // TableViewController.h #import <UIKit/UIKit.h> #import "DetailViewController.h" #im

我想将tableView indexPath分配给视图控制器变量之一。然而,对我来说很奇怪,它指定了其中一个,无论我选择哪一行,它总是指定0。 正如您在下面的代码中看到的,iVC.virdsection=indexPath.row工作得非常好,但sVC2.evradID=indexPath.row始终为0

//
//  TableViewController.h

#import <UIKit/UIKit.h>
#import "DetailViewController.h"
#import "SubViewController.h"

@interface TableeViewController : UITableViewController
@property (nonatomic,strong)NSArray *contentArray;
@property (strong,nonatomic)DetailViewController *detailViewController;
@property (strong,nonatomic)SubViewController *subViewController;
@end

//
//  TableViewController.m

#import "TableViewController.h"
#import "DetailViewController.h"
#import "SubViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController
@synthesize contentArray;
@synthesize detailViewController;
@synthesize subViewController;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    DetailViewController *iVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    self.detailViewController = iVC;

    iVC.virdSection = indexPath.row;
    iVC.navigationItem.title=[NSString stringWithFormat:@"%d.Vird",indexPath.row+1];

   SubViewController *sVC2 = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:[NSBundle mainBundle]];
    self.subViewController = sVC2;
    sVC2.evradID=indexPath.row;
    [self.navigationController pushViewController:iVC animated:YES];
}


Here is my SubViewController.h
//  SubViewController.h


#import <UIKit/UIKit.h>

@interface SubViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *evradLabel;
-(void)evradCall;
@property int evradID;
@end
//
//TableViewController.h
#进口
#导入“DetailViewController.h”
#导入“SubViewController.h”
@接口表视图控制器:UITableViewController
@属性(非原子,强)NSArray*contentArray;
@属性(强,非原子)DetailViewController*DetailViewController;
@属性(强,非原子)SubViewController*SubViewController;
@结束
//
//TableViewController.m
#导入“TableViewController.h”
#导入“DetailViewController.h”
#导入“SubViewController.h”
@接口TableViewController()
@结束
@TableViewController的实现
@合成内容数组;
@综合控制器;
@综合子视图控制器;
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
DetailViewController*iVC=[[DetailViewController alloc]initWithNibName:@“DetailViewController”捆绑包:[NSBundle mainBundle]];
self.detailViewController=iVC;
iVC.virdSection=indexPath.row;
iVC.navigationItem.title=[NSString stringWithFormat:@“%d.Vird”,indexath.row+1];
SubViewController*sVC2=[[SubViewController alloc]initWithNibName:@“SubViewController”捆绑:[NSBundle mainBundle]];
self.subViewController=sVC2;
sVC2.evradID=indexPath.row;
[self.navigationController pushViewController:iVC动画:是];
}
这是我的子视图控制器
//子视图控制器.h
#进口
@接口子ViewController:UIViewController
@属性(弱,非原子)IBUILabel*evradLabel;
-(无效)evradCall;
@埃弗拉迪的财产;
@结束

愚蠢的问题,但我以前也遇到过这样的情况,
sVC2
nil吗?实例化sVC2时可能会遇到问题


从发布的代码中很难判断发生了什么。

第0行是第一行。如果您记录
indexPath.row
,它可能会显示所有行的索引。0在技术上是正确的。试试这个代码

NSUInteger row = 0;
NSUInteger sect = indexPath.section;
for (NSUInteger i = 0; i < sect; ++ i){
sVC2.evradID = i;
}
nsu整数行=0;
nsupinteger sect=indexPath.section;
对于(整数i=0;i

(我发现了这个

如何测试sVC2是否为nill?我还放入了subviewController.evradID,但它仍然为0。您可以执行
NSLog(@“%@”,sVC2)
并查看结果。nil对象的属性将返回0。您是否认为这是错误的,因为值为零?如果是,您是否知道索引路径既是一行又是一节?每个节中的第一行都编号为“0行”。因此,如果您的表被划分为多个部分,那么每个部分的第一行都是数字0。很难说您的表是如何设置的。您好,比尔,我只想将indexPath.row分配给我的变量sVC2.evradID.Hello Chris,这不是我的问题