我想将 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