本项目主要是 使用 tableview 控件,使用 plist里所定义的 dictionary 格式文件 显示
// 通过 nsbundle 将 heros.plist 文件 取出到 一个 数组 array 里
NSString *file=[[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]; NSArray *arraydic=[[NSArray alloc]initWithContentsOfFile:file]; NSMutableArray *arraymut=[NSMutableArray arrayWithCapacity:arraydic.count]; for(NSDictionary *dic in arraydic) { Hero *hero=[Hero herowithdic:dic]; [arraymut addObject:hero]; } array=[arraymut copy];
//设置 tableview 里 的cell 样式
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"cell"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier]; if(!cell) { UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]; } Hero *hero=self.array[indexPath.row]; // 设置 cell 的 附控件 样式 cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text=hero.name; cell.detailTextLabel.text=hero.intro; cell.detailTextLabel.textColor = [UIColor orangeColor]; cell.imageView.image=[UIImage imageNamed:hero.icon]; return cell; }
// 调用方法 控制 导航控制栏 是否 隐藏
-(BOOL)prefersStatusBarHidden { return YES; }
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqual:@"show"]) { NSIndexPath *index= [self.tableview indexPathForSelectedRow]; //NSLog(@"%d",index.row); Hero *hero=[self.array objectAtIndex:index.row]; DetailView *de=segue.destinationViewController;
// 给第二个 view 传送 数据 [de setValue:hero.intro forKey:@"strTitle"]; } }