私は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」と表示されます。