У меня есть UIViewController
называется ForthViewControler с двумя кнопки СВОЙСТВ:
.h файла:Отображение двух различных массивов при нажатии кнопки различных
#import <UIKit/UIKit.h>
@interface ForthViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIButton* imgBtn;
@property (nonatomic, strong) IBOutlet UIButton* imgBtn2;
@end
В файле .m я есть те METHODE, что подключенный к кнопке в Строитель Интерфейс:
#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];
}
Эти methodes приводят к 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` даного.
Проблема в том, что каждый раз, когда я нажимаю одну из двух кнопок (в моем файле FortViewController nib), это приводит к тому же массиву ... Я буду рад узнать, что я делаю неправильно?
Извините за длинный пост, я хочу дать максимум информации :)
Thanks.
Строка 'ForthViewController * tivc1 = [[ForthViewController alloc] initWithNibName: @" ForthViewController "bundle: nil];' создает * * новый ** объект. Затем вы сразу же проверяете кнопки, выбранные в объекте, который пользователь никогда не касался. –