所以我想填充一個UIViewController從另一個tableviewController推送tableview。我知道我必須寫一個if語句,但是在這方面遇到了問題...重申我猜我的問題是如何填充tableViewController中的一個detailedViewController中的tableView?請參閱下面的代碼以供參考,如果我沒有提供所需的一切,我可以提前道歉。我可能會完全朝這個方向發展。如果聲明detailViewController與tableview
感謝您的任何和所有輸入!
/* DetaiLViewController.m file */
#import "DetaiViewController.h"
#import "RecommendationsCell.h"
/* .......... */
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.title = _DetailModal[0];
/*WHAT IS THE IF STATEMENT ???!! */
if ([self.navigationItem.title isEqualToString: @"London, United Kingdom"]) {
DetailedImages.image = /* HERE IS AN ARRAY OF London IMAGES to DISPLAY ON DETAILEDVIEWCONTROLLER */
IF....
DetailedImages.image = /* HERE IS AN ARRAY OF LONDON IMAGES to DISPLAY ON DETAILEDVIEWCONTROLLER */
IF....
DetailedImages.image = /* HERE IS AN ARRAY OF BERLIN IMAGES to DISPLAY ON DETAILEDVIEWCONTROLLER */
IF...
DetailedImages.image = /* HERE IS AN ARRAY OF PERTH IMAGES to DISPLAY ON DETAILEDVIEWCONTROLLER */
IF...
THE REMAINING ARRAYS FOR EACH CELL FROM TABLEVIEWCONTROLLER ETC.......
];
}
/* HERE IS ARRAY FROM TABLEVIEWCONTROLLER THAT PUSHES TO DETAILEDVIEWCONTROLLER */
/* _Images = @[@"london.jpeg",
@"berlin.jpeg",
@"perth.jpeg",
@"beijing.jpeg",
@"Madrid-26512.jpg",
@"barcelona.jpeg",
@"norway1_2141015b.jpg",
@"sweden.jpeg",]; */
/* HERE IS ARRAY FROM TABLEVIEWCONTROLLER THAT PUSHES TO DETAILEDVIEWCONTROLLER */
/* _Title = @[@"London, United Kingdom",
@"Berlin, Germany",
@"Perth, Australia",
@"Beijing, China",
@"Madrid, Spain",
@"Barcelona, Spain",
@"Oslo, Norway",
@"Denmark, Sweden",]; */
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _Title.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"RecommendationsCell";
RecommendationsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Title[row];
//cell.DescriptionLabel.text = _Description[row];
cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];
return cell;
}
/* DetailedViewController.h file */
@interface DetaiViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UIImageView *DetailedImages;
}
//@property (nonatomic, strong) NSArray *Description;
@property (nonatomic, strong) NSArray *Title;
@property (nonatomic, strong) NSArray *Images;
@property (strong, nonatomic) NSArray *DetailModal;
@end
/* DetailedViewController Cell.h file */
@interface RecommendationsCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
@property (strong, nonatomic) IBOutlet UIImageView *ThumbImage;
//@property (strong, nonatomic) IBOutlet UILabel *DescriptionLabel;
@property (strong, nonatomic) IBOutlet UIImageView *DetailedImages;
@end
好的,謝謝。創建對象是有道理的。所以只是爲了澄清,如果我的tableViewController有8個單元格,我會創建8個NSObject類(標題)...然後使用父視圖控制器的實現文件中的NSArray圖像集創建每個對象的實例?不要挑剔,但也許快速的代碼示例可能有幫助...我顯然是一個初學者。再次感謝! – user3708224 2014-08-27 18:30:40
你的表格單元數將取決於你的數組中的項目數量,所以是的,如果你的數組中有8個對象,你將有8個單元格。什麼代碼需要幫助? – 2014-08-27 20:08:10