我讀過許多後仍無法將數據從我的plist推到我的DetailViewController數據推送到的DetailView控制器
我試圖在模擬器上運行,顯示CUICatalog:無效的資產名稱提供:(空)
這完全是我的CustomTableViewController.m
#import "CustomTableViewController.h"
#import "customCell.h"
#import "DetailViewController.h"
@interface CustomTableViewController()<UISearchDisplayDelegate, UISearchBarDelegate>
@property (nonatomic, strong)NSArray *contactsArray;
@property (nonatomic, strong)NSDictionary *contact;
@end
@implementation CustomTableViewController
@synthesize contactsArray, contact;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self){
//Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:@"contacts" ofType:@"plist"];
contactsArray = [NSArray arrayWithContentsOfFile:path];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [contactsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
customCell *customCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
contact = contactsArray[indexPath.row];
NSString *firstName = contact[@"firstName"];
NSString *lastName = contact[@"lastName"];
NSString *imageName = contact[@"imageName"];
NSString *cost = contact[@"cost"];
NSString *property = contact[@"property"];
UIImage *image = [UIImage imageNamed:imageName];
customCell.customFirstNameLabel.text = firstName;
customCell.customLastNameLabel.text = lastName;
customCell.customImageView.image = image;
customCell.customcostLabel.text = cost;
customCell.custompropertyLabel.text = property;
return customCell;
}
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Card Background.png"]];
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
希望有人能幫助!!!!非常感謝
這是除了我的PLI ST
<dict>
<key>firstName</key>
<string>【騎士】聖夜型トール</string>
<key>lastName</key>
<string>傭兵</string>
<key>imageName</key>
<string>【騎士】聖夜型トール.png</string>
<key>property</key>
<string>闇</string>
<key>rare</key>
<string>UR</string>
<key>cost</key>
<string>5</string>
<key>skillName</key>
<string>制裁剣=討伐絆人(ホーリーデストロイ)</string>
<key>normalSkill</key>
<string>敵単體物理6,541闇ダメージ</string>
<key>awrokenSkill</key>
<string>敵単體物理10,851闇ダメージ、チェイン數で威力アップ</string>
<key>hp</key>
<string>1385</string>
<key>pa</key>
<string>231</string>
<key>ma</key>
<string>0</string>
<key>heal</key>
<string>0</string>
</dict>
,我需要把所有這些都以DetailViewController由於我在CustomeTableViewController選定行,現在是什麼出現
我我DetailViewController.h
@interface DetailViewController : UIViewController{
IBOutlet UIScrollView *scroller;
}
@property (strong, nonatomic) IBOutlet UIImageView *imageName;
@property (strong, nonatomic) IBOutlet UILabel *firstName;
@property (strong, nonatomic) IBOutlet UILabel *lastName;
@property (strong, nonatomic) IBOutlet UILabel *property;
@property (strong, nonatomic) IBOutlet UILabel *rare;
@property (strong, nonatomic) IBOutlet UILabel *cost;
@property (strong, nonatomic) IBOutlet UILabel *hp;
@property (strong, nonatomic) IBOutlet UILabel *pa;
@property (strong, nonatomic) IBOutlet UILabel *heal;
@property (strong, nonatomic) IBOutlet UILabel *ma;
@property (strong, nonatomic) IBOutlet UILabel *skillName;
@property (strong, nonatomic) IBOutlet UILabel *normalSkill;
@property (strong, nonatomic) IBOutlet UILabel *awrokenSkill;
@property int selectedRow;
@end
然後DetailViewController。 m,我這樣做了
@implementation DetailViewController
@synthesize imageName;
@synthesize firstName;
@synthesize lastName;
@synthesize property;
@synthesize rare;
@synthesize cost;
@synthesize hp;
@synthesize pa;
@synthesize heal;
@synthesize ma;
@synthesize skillName;
@synthesize normalSkill;
@synthesize awrokenSkill;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(600, 800)];
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contacts" ofType:@"plist"]];
NSArray *imageArray = [picturesDictionary objectForKey:@"imageName"];
imageName.image = [UIImage imageNamed:[imageArray objectAtIndex:self.selectedRow]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
再次感謝任何幫助!
提供的代碼爲:'objectInListAtIndex '你在'prepareForSegue'中打電話。此外你的問題還不清楚,你是否在'DetailViewController'裏面打印了'selectedRow',你是否得到了任何值或nil?它的數據類型是什麼? –
@SimonMcLoughlin感謝您的幫助^^ – roylam
這到底是什麼?老兄,千萬不要在評論中發佈這樣的內容,編輯你的問題,並使用代碼格式,以便可讀。更進一步,這不能回答我的評論。你有什麼問題,你有一個plist,並希望將它發送給另一個vc。什麼是不工作,你不能從plist得到的對象,你不能讀對方等。請再次閱讀我的第一個評論,並張貼我要求的代碼/答案 –