您好我正在创建一个与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;
}
}
}
}
The sample image I want like this
我想要重复视图和按后退按钮,重复的tableViewCell中显示所选的单元格。
答案 0 :(得分:1)
我在我的应用程序中做了同样的事情。我可以帮助你...... 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);
}
}
答案 1 :(得分:0)
用户在选择行的位置保存动作,例如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];
}
}
等等......