Ios 不使用pushViewController将数据传递到另一个文件
我正在尝试将数据从Myfile推送到SDWebImageDataSource并推送到SDWebImageRootViewController(视图)。我有一个问题,我无法传递数据。我使用了Ios 不使用pushViewController将数据传递到另一个文件,ios,pushviewcontroller,sdwebimage,Ios,Pushviewcontroller,Sdwebimage,我正在尝试将数据从Myfile推送到SDWebImageDataSource并推送到SDWebImageRootViewController(视图)。我有一个问题,我无法传递数据。我使用了setImageLink方法,但在NSInteger方法中获得了imageLink值(null),为什么会发生这种情况?我应该用不同的方法吗 Myfile.h @property (nonatomic, retain) NSString *image; Myfile.m - (void)showSDWebI
setImageLink
方法,但在NSInteger
方法中获得了imageLink值(null),为什么会发生这种情况?我应该用不同的方法吗
Myfile.h
@property (nonatomic, retain) NSString *image;
Myfile.m
- (void)showSDWebImageSample
{
SDWebImageDataSource *imageController = [[SDWebImageDataSource alloc] init];
[imageController setImageLink:image];
[imageController release];
NSLog(@"imagelink are: %@", imageController.imageLink);
SDWebImageRootViewController *newController = [[SDWebImageRootViewController alloc] init];
[[self navigationController] pushViewController:newController animated:YES];
[newController release];
}
SDWebImageDataSource.m
-(void)setImageLink:(NSString *)imageLinkStr
{
imageLink = imageLinkStr;
//// I can see the value here
NSLog(@"111 %@ 111",imageLinkStr);
NSLog(@"222 %@ 222",imageLink);
}
- (NSInteger)numberOfPhotos {
////imageLink string is (null) Problem here
NSLog(@"222 %@ 222",imageLink);
images_ = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"http://farm3.static.flickr.com/2756/4464013736_524526b2b2_z.jpg", @"http://farm3.static.flickr.com/2756/4464013736_524526b2b2_s.jpg", nil], [NSArray arrayWithObjects:imageLink, imageLink, nil], nil];
NSInteger count = [images_ count];
return count;
}
- (void)imageAtIndex:(NSInteger)index photoView:(KTPhotoView *)photoView {
NSArray *imageUrls = [images_ objectAtIndex:index];
NSString *url = [imageUrls objectAtIndex:FULL_SIZE_INDEX];
[photoView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"photoDefault.png"]];
}
也许不是最好的解决方案,但您可以尝试以下方法:
-(void)setImageLink:(NSString *)imageLinkStr {
imageLink = imageLinkStr;
//// I can see the value here
NSLog(@"111 %@ 111",imageLinkStr);
NSLog(@"222 %@ 222",imageLink);
[[NSUserDefaults standardUserDefaults] setObject:imageLink forKey:@"image"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
- (NSInteger)numberOfPhotos {
NSString *importImage = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
////imageLink string is (null) Problem here
NSLog(@"222 %@ 222",importImage);
images_ = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"http://farm3.static.flickr.com/2756/4464013736_524526b2b2_z.jpg", @"http://farm3.static.flickr.com/2756/4464013736_524526b2b2_s.jpg", nil], [NSArray arrayWithObjects:importImage, importImage, nil], nil];
NSInteger count = [images_ count];
return count;
}
您忘记[[NSUserDefaults standardUserDefaults]同步];在里面setImageLink@Yanchi你是对的,我使用arc,所以不需要同步,但在这种情况下,你必须添加