从一个表视图到另一个表视图(使用 Xcode 4.2 和 iOS 5)。
第一页.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;
}
收藏夹控制器.h
@interface FavoritesController : UITableViewController
@property(nonatomic,strong)NSMutableArray * profilelist;
@end
收藏控制器.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;
}
故事板表视图
这是我得到的错误
2012-02-08 22:28:37.719 测试 [4668:f803] 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath:返回一个单元格:”