从tableview到另一个table view(使用Xcode 4.2和iOS 5)。Tableview跨越另一个tableview和自定义表格单元格不能显示
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 = @"[email protected]";
[profiles addObject:profile];
profile=[[Profiles alloc]init];
profile.profile_name = @"Jin-Aurora";
profile.biz_type_desc = @"Software";
profile.profile_address = @"682A";
profile.profile_email = @"[email protected]";
[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 dataSource必须从 返回一个单元格tableView:cellForRowAtIndexPath:'
嗨jmstone,我的代码是这样的。ProfileCell * cell =(ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){cell = [[ProfileCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];} ( – 2012-02-09 01:48:20
如果你没有得到任何单元格,在该方法中设置一个断点,看它是否被击中,否则,通常的罪魁祸首是你的数据源说该部分中没有任何行(请参阅numberOfRowsInSection方法返回) – jmstone617 2012-02-09 02:28:51
嗨jmstone,它返回我tableViewCellStyleDefault由于我把initWithStyle,我设置cell.textLabel.text = profile.profile _名称。它能够显示。但我想要显示自定义表格单元:(我应该为InitWithStyle放置自定义表格视图单元格? – 2012-02-09 03:29:10