2011-07-28 13 views
0

私は2つのtableviewコントローラを持っているアプリケーションを持っています。 2番目のtableviewコントローラでは、私は7つの値を保持し、私のtableviewのセルに表示される配列を作成しました。このテーブルビューセルでは、複数行の選択が可能です。しかし、私には1つの問題があります。複数の選択されたtableviewセルの値が、私の最初のtableviewコントローラに表示されるはずです。これはどのように可能ですか?私の前のコントローラの詳細テキストラベルにtableviewセルの複数の選択値を表示する方法

これは私の第二のコントローラクラスである:このクラスで

- (void)viewDidLoad { 
    daysarray =[[NSMutableArray alloc]initWithObjects:@"Every Monday",@"Every Tuesday",@"Every Wednesday",@"Every Thursday",@"Every Friday",@"Every Saturday",@"Every Sunday",nil]; 
    temp = [[NSDictionary alloc] initWithObjectsAndKeys:daysarray,@"arrValue",nil]; 
    arrayValues = [[NSMutableArray alloc] initWithObjects:@"Every Monday",@"Every Tuesday",@"Every Wednesday",@"Every Thursday",@"Every Friday",@"Every Saturday",nil]; 
    self.daysarray = arrayValues; 
    [arrayValues release]; 
    [super viewDidLoad]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [arrayValues count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    cell.textLabel.text = [daysarray objectAtIndex:indexPath.row]; 
    cell.accessoryType = ([indexPath isEqual:rowselection]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; 

    // Configure the cell... 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    self.rowselection = indexPath; 
    NSUInteger row = [indexPath row]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    if ([[tableView cellForRowAtIndexPath:indexPath ] accessoryType] == UITableViewCellAccessoryCheckmark) 
    { 
     [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone]; 
     [daysarray replaceObjectAtIndex:row withObject:@"0"]; 
    } 
    else 
    { 
     [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark]; 
     [daysarray replaceObjectAtIndex:row withObject:@"1"]; 
    } 
} 

、複数の行は、テーブルビューで選択されてもよいです。しかし、今度は、条件に応じて、最初のコントローラの詳細テキストラベルに選択した値を表示します。

つまり、(毎週月曜日、毎週火曜日、毎週水曜日、毎週木曜日、毎週金曜日、毎週土曜日、毎週日曜日)、詳細テキストに「毎日」が表示されます。ユーザーが(毎週月曜日、毎週火曜日、毎週水曜日、毎週木曜日、毎週金曜日)を選択すると、詳細テキストに「毎週」と表示されます。ユーザーが毎週土曜日に&を選択した場合、毎週日曜日に「毎週末」と表示されます。ユーザが任意のテキストを選択した場合、たとえば、ユーザが(毎週月曜日、毎週水曜日、毎週金曜日)を選択すると、「Every Mo、Wed、Fri」と表示されます。

答えて

0

最初のviewcontrollerから2番目のビューコントローラを作成した場合、最初のビューコントローラを最初のビューコントローラに代入することができます。最初のビューコントローラにデリゲートメソッドを実装し、プロトコルを2番目に宣言します。選択が完了したら、選択した値でデリゲートメソッドを呼び出します。

SecondViewController.hは次のように似ている必要があります。

@protocol SecondViewControllerDelegate; 

@interface SecondViewController 
{ 
id <SecondViewControllerDelegate>delegate; 
} 
@property (nonatomic, assign) id <SecondViewControllerDelegate>delegate; 


@protocol SecondViewControllerDelegate 

- (void) tableViewselected:(NSString *)value1 and:(NSString *)value2; 
@end 

SecondViewController.mを持っている必要があります:行がコール[delegate tableViewselected:value1 and:value2];

を選択した後

@synthesize delegate; 

を今、あなたは、メソッドを実装する必要がありますFirstViewControllerのtableViewselected:(NSString *)value1 and:(NSString *)value2;を呼び出してそれを処理します。

ここに私の要点があると思います。

関連する問題