【发布时间】:2012-02-08 14:36:50
【问题描述】:
从一个表视图到另一个表视图(使用 Xcode 4.2 和 iOS 5)。
FirstPage.h
#import "FavoritesController.h"
#import "Profiles.h"
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FavoritesController * favoriteview = [[FavoritesController alloc] init];
[favoriteview setTitle:@"Favorites"];
NSMutableArray * profiles = [[NSMutableArray alloc]init ];
profiles = [NSMutableArray arrayWithCapacity:20];
Profiles * profile = [[Profiles alloc]init];
profile.profile_name = @"Woot";
profile.biz_type_desc = @"Woot 1";
profile.profile_address = @"123, woot";
profile.profile_email = @"woot@woot.com";
[profiles addObject:profile];
profile=[[Profiles alloc]init];
profile.profile_name = @"Jin-Aurora";
profile.biz_type_desc = @"Software";
profile.profile_address = @"682A";
profile.profile_email = @"jin@jin.biz";
[profiles addObject:profile];
[self.navigationController pushViewController:favoriteview animated:YES];
favoriteview.profilelist = profiles;
}
FavoriesController.h
@interface FavoritesController : UITableViewController
@property(nonatomic,strong)NSMutableArray * profilelist;
@end
FavoriteController.m
#import "FavoritesController.h"
#import "Profiles.h"
#import "ProfileCell.h"
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.profilelist count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProfileCell";
ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Profiles * profile = [self.profilelist objectAtIndex:indexPath.row];
cell.nameLabel.text = profile.profile_name;
cell.biztypeLabel.text = profile.biz_type_desc;
// Configure the cell...
return cell;
}
故事板表格视图
- Picture of prototype cell xib with Identity inspector
- Picture of prototype cell xib with Attributes inspector
这是我得到的错误
2012-02-08 22:28:37.719 测试[4668:f803] 终止应用程序由于 未捕获的异常'NSInternalInconsistencyException',原因: 'UITableView 数据源必须返回一个单元格 tableView:cellForRowAtIndexPath:'
【问题讨论】:
标签: ios uitableview uistoryboard