【问题标题】:UITextfield in UITableview with Calendar value带有日历值的 UITableview 中的 UITextfield
【发布时间】:2012-11-26 04:34:19
【问题描述】:

我有一个关于使用日历中的选定值填充 UITableViewCell 的问题。所以我有这个tableview,它当然是在视图出现时创建的,正如我所说,我也有这个日历视图控制器。主要思想是用户可以在日历上选择一个日期,然后该值应该出现在 tableview 的文本字段中。

我有一个函数将选定的值从日历视图控制器返回到另一个视图控制器,但之后我无法使用该值填充 UITextField。

有任何想法或以前的类似经验吗?

这是日历视图控制器中使用的代码

-(void)giveString:(NSString*)string{
GradesViewController *grades = [[GradesViewController alloc]init];
[grades getString:string];
NSLog(@"String : %@",string);}

这是另一个视图中的类,我希望在位于 tableviewcell 中的文本字段中的日历中获取此字符串值

-(void)getString:(NSString*)string{
stringDate = string;
NSLog(@"String: %@",stringDate);}

这两个值都出现在日志中...

【问题讨论】:

  • “无法填充”是什么意思?你是如何尝试的?我们可以看看一些示例代码吗?
  • 我已经编辑了这个问题,并添加了它的主要部分......

标签: ios xcode ipad uitableview calendar


【解决方案1】:

你永远不会在[GradesViewController getString:string]中保留“字符串”

-(void)getString:(NSString*)string {
    stringDate = string;
    [stringDate retain];
    NSLog(@"String: %@",stringDate);
}

确保它也被释放,以确保垃圾收集将清理它。

【讨论】:

    【解决方案2】:

    如果您在tableviewcell cellForRowAtIndexpath 中声明了该文本字段,则需要在cellForRowAtIndexpath 中设置stringDate 值。如果您使用自定义 tableviewcell,则需要将该值传递给您 custome tableView 单元类,就像您从 CalendarViewController 调用其他 ViewController 的方式一样

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"cellId";
        UITableViewCell *tableCell = [tableView dequeueReusableCellWithIdentifier:cellId];
         if (tableCell == nil) {
            tableCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            UITextField *urlTxtFld = [[UITextField alloc] initWithFrame:CGRectMake(70, 10, 230, 120)];
    
            urlTxtFld.backgroundColor = [UIColor clearColor];
            urlTxtFld.text = stringDate // you need to set your text like this
            urlTxtFld.autocorrectionType = UITextAutocorrectionTypeNo;
            [qrCell addSubview:urlTxtView];
            [urlTxtFld release];
        }
    
     }
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2018-06-29
      • 1970-01-01
      相关资源
      最近更新 更多