0

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

2 回答 2

1

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

NSUInteger row = 0;
NSUInteger sect = indexPath.section;
for (NSUInteger i = 0; i < sect; ++ i){
sVC2.evradID = i;
}

(我在这里找到了这个)

于 2013-03-11T21:58:10.193 回答
0

Dumb question, but I've had it happen to me before, is sVC2 nil? You could have a problem instantiating sVC2.

It's kind of hard to tell what's going on from code posted.

于 2013-03-11T21:16:14.163 回答