[英]Select Multiple cell in tableView and display the selected cell in another tableView Cell as a label?
您好,我正在创建与iOS默认警报相关的应用。 我在tableView中选择了多个单元格。 如果单击后退按钮,则选定的单元格将在tableViewCell中显示为另一个视图中的标签。 我正在使用故事板。 这个怎么做?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
[myIndexArray addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
}
else
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
for(int i=0; i<myIndexArray.count; i++)
{
if([[myIndexArray objectAtIndex:i]intValue]== indexPath.row)
{
[myIndexArray removeObjectAtIndex:i];
break;
}
}
}
}
我想要类似“重复视图”的内容,然后按返回按钮,所选单元格将显示在“重复” tableViewCell中。
我在我的应用中做了同样的事情。 我能帮你...
RepeatDayViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (UITableViewCellAccessoryNone == cell.accessoryType )
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
NSNumber *dayNumber = [NSNumber numberWithInteger:indexPath.row];
[self.repeatDays addObject:dayNumber];
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
NSNumber *dayNumber = [NSNumber numberWithInteger:indexPath.row];
[self.repeatDays removeObject:dayNumber];
}
}
我正在将self.repeatDays
传递给AddAlarmViewController
在
AddAlarmViewController
我有这样的数组
_days = [[NSArray alloc ]initWithObjects:@"Sun",@"Mon",@"Tue",@"Wed",@"Thu",@"Fri",@"Sat",nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.repeatDays count])
{
NSMutableArray *repeatDays = [NSMutableArray array];
for (NSNumber *dayNumber in self.repeatDays)
{
[repeatDays addObject:[_days objectAtIndex:[dayNumber integerValue]]];
}
NSString *repeatLabel = [repeatDays componentsJoinedByString:@" "];
cell.detailTextLabel.text = repeatLabel;
}
else
{
cell.detailTextLabel.text = NSLocalizedString(@"Never",nil);
}
}
用户选择行的位置将操作保存到任何软件,例如NSUserDefaults
在里面
-(void)viewDidAppear:(BOOL)animated{
UITableViewCell* testCell = [azanTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
if ([[NSUserDefaults standardUserDefaults]boolForKey:@"testCell"]==YES) {
testCell.accessoryType = UITableViewCellAccessoryCheckmark;
testCell .textLabel.textColor = [UIColor colorWithRed:0.22 green:0.33 blue:0.53 alpha:1.0];
}
}
等等...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.