【发布时间】:2011-07-27 12:10:21
【问题描述】:
我有一个类,其中有一个表视图,在表视图中我通过数组显示值。当我运行我的应用程序并选择 tableview 的单元格时,一次只选择一个特定的单元格,并且它的值显示在我以前的控制器的 detailtextlabel 中。我希望一次启用多个选择。
现在我正在这样做。这是我希望我的多个表格视图单元格应该被选中的类:
TAddAlarmNewController.m
- (void)viewDidLoad {
days =[[NSMutableArray alloc]initWithObjects:@"Every Monday",@"Every Tuesday",@"Every Wednesday",@"Every Thursday",@"Every Friday",@"Every Saturday",@"Every Sunday",nil];
temp = [[NSDictionary alloc] initWithObjectsAndKeys:days,@"arrValue",nil];
[super viewDidLoad];
}
在 days 数组中我存储 7 个值,在 rowinsection 的 no 中我正在计算数组:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [days count];
}
在cellforrowatindexpath方法中:
- (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 = [days objectAtIndex:indexPath.row];
cell.accessoryType = ([indexPath isEqual:rowselection]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}
在此我将数组添加到单元格的文本标签中。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//rowselection is an indexpath variable.
self.rowselection = indexPath;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadData];
for (int i=0; i<[[self.navigationController viewControllers] count]; i++)
{
UIViewController *aController = [[self.navigationController viewControllers]objectAtIndex:i];
if ([aController isKindOfClass:[TAddAlarmController class]])
{
TAddAlarmController *addalarm = (TAddAlarmController*)aController;
newrepeat =(NSString*)[[days objectAtIndex:indexPath.row] retain];
[addalarm refreshTableToSetDetailText:newrepeat];
}
}
//TAddAlarmController is the previous controller in which detailtextlabel i am setting the next controller value.
}
【问题讨论】:
-
@vijay,1 票赞成良好的链接。
标签: iphone objective-c tableview