Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone应用程序代理无法正常工作_Iphone_Date_Delegates - Fatal编程技术网

iPhone应用程序代理无法正常工作

iPhone应用程序代理无法正常工作,iphone,date,delegates,Iphone,Date,Delegates,我是iPhone开发新手。我正在将日期转换为所需的格式,并将其设置为代理,然后在另一个视图中获取其值。当我试图从委托获取值时,会话将重新启动。如果我在set委托中设置了原始日期而不是格式化日期,那么我就可以在另一个视图中获取该值。如果我也给出了任何静态字符串值,那么我也能够返回静态字符串值 只有设置了字符串格式的日期,会话才会重新启动。如果我打印并检查格式化日期的值,它只打印正确的格式化日期。这是我的日期转换代码 NSString *dateval=[[stories objectAtIndex

我是iPhone开发新手。我正在将日期转换为所需的格式,并将其设置为代理,然后在另一个视图中获取其值。当我试图从委托获取值时,会话将重新启动。如果我在set委托中设置了原始日期而不是格式化日期,那么我就可以在另一个视图中获取该值。如果我也给出了任何静态字符串值,那么我也能够返回静态字符串值

只有设置了字符串格式的日期,会话才会重新启动。如果我打印并检查格式化日期的值,它只打印正确的格式化日期。这是我的日期转换代码

NSString *dateval=[[stories objectAtIndex: storyIndex] objectForKey:@"date"];

NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];

[inputFormatter setDateFormat:@"EEE, MMM dd, yyyy"];

NSDate *inputDate = [inputFormatter dateFromString:dateval];

NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];

[outputFormatter setDateFormat:@"MMMM dd"];

NSString *outputDate = [outputFormatter stringFromDate:inputDate];  

AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

[delegate setCurrentDates:outputDate];
编辑 这将显示在控制台中

内部视图没有加载

[Session started at 2010-04-21 19:12:53 +0530.]
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 4216.
(gdb) 
从另一个角度看

 - (void)viewDidLoad {
NSLog(@"inside view did load");
AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *titleValue=[delegate getCurrentDates];
self.navigationItem.title =titleValue ;
}

get不能正常工作。如果我给出任何静态字符串或“dateval”,它可以正常工作。

outputDate
似乎没有被保留,因此该值在事件循环结束时丢失(因为NSAutoreleasePool)

您应该保留
outputDate
,以避免在委托中使用类似的内容释放它:

- (void)setCurrentDates:(NSString *)value {
    [value retain]; // <- Retain new value
    [date release]; // <- Release old value;
    date = value;
}
-(void)setCurrentDates:(NSString*)值{

[value retain];//您所说的“会话重新启动”是指应用程序崩溃吗?出现了什么错误?在获取值的另一个视图中显示代码。我已修复setter代码,使其具有正确的保留/释放顺序。我能够从您以前的代码本身理解您试图说的内容。谢谢,它工作得非常好。