1

fromlensInt =1で my ViewController1(これはテーブル ビューです) に渡すと、 lensInt (整数) が 0 にリセットされMenuViewControllerます。My Menu View Controller は、背景をスライドさせる Facebook のようなものです。また、MyViewController1はナビゲーション コントローラー バーに埋め込まれています。整数のみが渡されるとリセットされ@implementation TableViewControllerます(ブレークポイントを使用してデバッグします)。

私のViewController1.h

#import <UIKit/UIKit.h>

@interface ViewController1 : UITableViewController{
NSMutableArray *ACUVUE;
NSMutableArray *BAUSCH_LOMB;
int lensInt;

}

私のViewController1.m

#import "ViewController1.h"
@implementation ViewController1
@synthesize lensInt;  

- (void)viewDidLoad
{

ACUVUE =[[NSMutableArray alloc]
         initWithObjects:@"1-DAY ACUVUE DEFINE",@"1-DAY ACUVUE ASTIGMATISM", nil];

BAUSCH_LOMB=[[NSMutableArray alloc]
             initWithObjects:@"B+L PURE VISION",@"B+L PURE VISION MULTIFOCAL",@"B+L PURE VISION TORIC",nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

if(self.lensInt == 0){
    return [ACUVUE count];}
if(self.lensInt == 1){
    return [BAUSCH_LOMB count];}

[self.tableView reloadData];}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];  }
// Configure the cell...

if(self.lensInt == 0){
    cell.textLabel.text = [ACUVUE objectAtIndex:indexPath.row];}

if(self.lensInt == 1){
    cell.textLabel.text = [BAUSCH_LOMB objectAtIndex:indexPath.row];}


//---------- CELL BACKGROUND IMAGE -----------------------------
UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.frame];
UIImage *image = [UIImage imageNamed:@"LightGrey.png"];
imageView.image = image;
cell.backgroundView = imageView;
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];



//Arrow
cell.accessoryType = UITableViewCellAccessoryNone;

return cell;}

@end

私のMenuViewController.m

#import "MenuViewController.h"
#import "ECSlidingViewController.h"
#import "ViewController1.h"

@interface MenuViewController ()

@property (strong, nonatomic) NSArray *menu;
@property (strong, nonatomic) NSArray *section1;
@property (strong, nonatomic) NSArray *section2;
@property (strong, nonatomic) ViewController1 *lens;



@end

@implementation MenuViewController
@synthesize lens;
@synthesize menu, section1, section2;



-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

tableView.backgroundColor = [UIColor darkGrayColor];
cell.contentView.backgroundColor = [UIColor darkGrayColor];
cell.textLabel.textColor =[UIColor whiteColor];
tableView.separatorColor =[UIColor blackColor];}


- (void)viewDidLoad
{    [super viewDidLoad];


self.section1 = [NSArray arrayWithObjects:@"Acuvue", @"Bausch + Lomb", nil];

self.section2 = [NSArray arrayWithObjects:@"Daily", @"Monthly", nil];

self.menu = [NSArray arrayWithObjects:self.section1, self.section2, nil];


[self.slidingViewController setAnchorRightRevealAmount:190.0f];
self.slidingViewController.underLeftWidthLayout = ECFullWidth;}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [self.menu count]; }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    
if (section == 0) {

    return [self.section1 count];

} else if (section == 1) {

    return [self.section2 count];
}}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {


if (section == 0) {

    return @"Contact Lens Brand";

} else if (section == 1) {

    return @"Contact Lens Type";
}

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; }

if (indexPath.section == 0) {

    cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.section1 objectAtIndex:indexPath.row]];

} else if (indexPath.section == 1) {


    cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.section2 objectAtIndex:indexPath.row]];
}




return cell;}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


UIViewController *newTopViewController;

if (indexPath.section == 0) {






    if([[section1 objectAtIndex:indexPath.row] isEqual:@"Acuvue"]){

        lens.lensInt= 0 ;



    }

    if([[section1 objectAtIndex:indexPath.row]isEqual:@"Bausch + Lomb"]){

        lens.lensInt = 1 ;


    }



    NSString *identifier = [NSString stringWithFormat:@"product"];

    newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];



} else if (indexPath.section == 1) {



    NSString *identifier = [NSString stringWithFormat:@"product"];


    newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];

}


[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = newTopViewController;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];}];

}

@end
4

1 に答える 1

0

prepareForSegueストーリーボードを使用している場合は、ビュー間でデータを渡す必要があります。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
    {
        // Get reference to the destination view controller
        YourViewController *vc = [segue destinationViewController];

        // Pass object to your view controller here
        [vc setMyObjectHere:object];
    }
}
于 2013-03-08T07:21:15.327 に答える