【发布时间】:2011-07-28 06:32:24
【问题描述】:
我有一个应用程序,其中有 2 个 tableview 控制器。在第二个 tableview 控制器中,我创建了一个包含 7 个值并显示在我的 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"];
}
}
在这个类中,可以在表格视图中选择多行。但现在我想根据条件在第一个控制器的详细文本标签中显示所选值。
也就是说,如果用户选择(每周一、每周二、每周三、每周四、每周五、每周六、每周日),则在详细信息文本中应显示“每天”。如果用户选择(每周一、每周二、每周三、每周四、每周五),那么它应该在详细信息文本中显示“每个工作日”。如果用户选择每个星期六和每个星期日,它应该显示“每个周末”。如果用户选择任何随机文本,那么它应该显示该特定文本,例如,如果用户选择(每周一、每周三、每周五),那么它应该显示“每周一、周三、周五”。这怎么可能。
【问题讨论】:
标签: iphone objective-c