我有一个UIViewController
名为 ForthViewControler 的两个按钮属性:
.h 文件:
#import <UIKit/UIKit.h>
@interface ForthViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIButton* imgBtn;
@property (nonatomic, strong) IBOutlet UIButton* imgBtn2;
@end
在 .m 文件中,我有那些连接到 Interface Builder 中的按钮的方法:
#import "SDWebImageRootViewController.h"
@implementation ForthViewController
@synthesize imgBtn, imgBtn2;
-(IBAction)menueBtnAction:(id)sender
{
SDWebImageRootViewController* tivc1 = [[SDWebImageRootViewController alloc] initWithNibName:@"SDWebImageRootViewController" bundle:nil];
[self.navigationController pushViewController:tivc1 animated:NO];
}
-(IBAction)menueBtnActionAfter:(id)sender
{
SDWebImageRootViewController* tivc1 = [[SDWebImageRootViewController alloc] initWithNibName:@"SDWebImageRootViewController" bundle:nil];
[self.navigationController pushViewController:tivc1 animated:NO];
}
这些方法通向 SDWebImageRootViewController。
这就是我在 SDWebImageRootViewController:
.h 文件中的内容:
#import <UIKit/UIKit.h>
#import "KTThumbsViewController.h"
@class SDWebImageDataSource;
@interface SDWebImageRootViewController : KTThumbsViewController
{
@private
SDWebImageDataSource *images_;
UIWindow *window_;
}
@end
.m 文件:
#import "SDWebImageRootViewController.h"
#import "SDWebImageDataSource.h"
@interface SDWebImageRootViewController ()
@end
@implementation SDWebImageRootViewController
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"SDWebImage Sample";
images_ = [[SDWebImageDataSource alloc] init];
[self setDataSource:images_];
}
最后,在 SDWebImageDataSource 文件中我有这个:
.h 文件:
#import <Foundation/Foundation.h>
#import "KTPhotoBrowserDataSource.h"
@interface SDWebImageDataSource : NSObject <KTPhotoBrowserDataSource>
{
NSMutableArray *images_;
}
@end
.m 文件:
#import "SDWebImageDataSource.h"
#import "KTPhotoView+SDWebImage.h"
#import "KTThumbView+SDWebImage.h"
#import "ForthViewController.h"
#define FULL_SIZE_INDEX 0
#define THUMBNAIL_INDEX 1
@implementation SDWebImageDataSource
- (id)init
{
self = [super init];
if (self)
{
// Create a 2-dimensional array. First element of
// the sub-array is the full size image URL and
// the second element is the thumbnail URL.
ForthViewController* tivc1 = [[ForthViewController alloc] initWithNibName:@"ForthViewController" bundle:nil];
if (tivc1.imgBtn.selected == YES)
{
images_ = [[NSMutableArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"http://farm6.static.flickr.com/5181/5554192246_e7cf81fb00_z.jpg", @"http://farm6.static.flickr.com/5181/5554192246_e7cf81fb00_s.jpg", nil],
[NSArray arrayWithObjects:@"http://farm6.static.flickr.com/5260/5554955879_01bfab9aeb_z.jpg", @"http://farm6.static.flickr.com/5260/5554955879_01bfab9aeb_s.jpg", nil],
[NSArray arrayWithObjects:@"http://farm6.static.flickr.com/5051/5556628277_f883fa1078_z.jpg", @"http://farm6.static.flickr.com/5051/5556628277_f883fa1078_s.jpg", nil], nil];
}
else
{
if (tivc1.imgBtn2.selected == YES)
{
images_ = [[NSMutableArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"http://dl.dropbox.com/u/6089026/icon2.png", @"http://dl.dropbox.com/u/6089026/icon2.png", nil],
[NSArray arrayWithObjects:@"http://farm4.static.flickr.com/3427/3192205971_0f494a3da2_o.jpg", @"http://farm4.static.flickr.com/3427/3192205971_b7b18558db_s.jpg", nil],
[NSArray arrayWithObjects:@"http://farm2.static.flickr.com/1316/4722532733_6b73d00787_z.jpg", @"http://farm2.static.flickr.com/1316/4722532733_6b73d00787_s.jpg", nil],
[NSArray arrayWithObjects:@"http://farm2.static.flickr.com/1200/591574815_8a4a732d00_o.jpg", @"http://farm2.static.flickr.com/1200/591574815_29db79a63a_s.jpg", nil],
[NSArray arrayWithObjects:@"http://dl.dropbox.com/u/6089026/mika4.png", @"http://dl.dropbox.com/u/6089026/mika4.png", nil], nil];
}
}
}
return self;
}
#pragma mark -
#pragma mark KTPhotoBrowserDataSource
- (NSInteger)numberOfPhotos
{
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)thumbImageAtIndex:(NSInteger)index thumbView:(KTThumbView *)thumbView {
NSArray *imageUrls = [images_ objectAtIndex:index];
NSString *url = [imageUrls objectAtIndex:THUMBNAIL_INDEX];
[thumbView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"photoDefault.png"]];
}
@end
如您所见,我尝试调用 ForthViewController 并将两个按钮用于“f”语句。
问题是每次我按下两个按钮之一(在我的 ForthViewController nib 文件中)它都会导致相同的数组......我会很高兴知道我做错了什么?
抱歉发了这么长的帖子,我想提供最详细的信息:)
谢谢。