【问题标题】:Select Multiple cell in tableView and display the selected cell in another tableView Cell as a label?在tableView中选择多个单元格并将另一个tableView单元格中的选定单元格显示为标签?
【发布时间】:2013-02-20 08:35:47
【问题描述】:

您好,我正在创建一个与 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 中。

【问题讨论】:

    标签: iphone ios objective-c uitableview


    【解决方案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);
                }
    
    }
    

    【讨论】:

    • 谢谢,我会检查并回复你
    • @Anil 你能给我任何样品吗?谢谢
    • @Anil 我已经试过了..我想要警报应用程序的样本。请传给我
    【解决方案2】:

    无论何时用户选择一行保存操作,如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];
    }
    
    }
    

    等等……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2015-04-20
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      相关资源
      最近更新 更多